How to split A string By LastIndexOf()
in VBA
I have a string which can have these kind of values
Dim input As String
input = "customName_D3"
input = "Custom_Name_D3"
input = "my_Custom_Name_D3"
like it can have many "_"
in it but after last"_"
it contains cell name
I want to split this string to get cell name and other remaning part as two different strings
something like
cellName = D3
remainingString = my_custom_Name
The VBA Split Function is used is to split a string of text into an array. The text is split based on a given delimiter – e.g. a comma, space, colon etc. You can see that each item separated by the colon sign. We call the colon sign the delimiter.
Step 2: Declare three variables. Step 3: Now, for the defined variable, My Text assigns the word “My Name is Excel VBA.” Step 4: Now, apply the VBA Split String function for the “My Result” variable. Step 5: Expression is our text value.
Dim strInput As String
Dim strName As String
Dim strCellAddress As String
Dim iSplit As Integer
strInput = "my_Custom_Name_D3"
iSplit = InStrRev(strInput, "_")
strName = Left(strInput, iSplit - 1)
strCellAddress = Mid(strInput, iSplit + 1)
MsgBox "Name: " & vbTab & strName & vbCrLf & "Cell: " & vbTab & strCellAddress
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With