String Split Not Working?

medberg

New Member
Joined
Jul 29, 2011
Messages
30
Hey everyone,

I have a piece of code that is frustrating because I have no idea why it is not working as intended. I basically have a string that I need to split on a delimiter, ":". When I split it into the array, the array is empty. Here is the code.
Code:
If InStr(1, LastTextRange, ":", 1) > 0 Then
        Dim rangeSplit() As String
        rangeSplit() = Split(CStr(LastRangeText), ":")
        Application.EnableEvents = False
        Application.Undo
        Application.EnableEvents = True
        Exit Sub
    End If

The string LastTextRange is what should contain a ":", and it does sometimes. If it does it falls into the if statement and rangeSplit should contain the values on either side of the ":". ANy help would be appreciated, thanks!
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Try

Code:
If InStr(1, LastTextRange, ":", 1) > 0 Then
        Dim rangeSplit As Variant
        rangeSplit = Split(CStr(LastRangeText), ":")
        Application.EnableEvents = False
        Application.Undo
        Application.EnableEvents = True
        Exit Sub
End If
 
Upvote 0
Hey,

First of all I would like to note I hade a typo in the code I pasted, I had the name wrong on the string. Fixing that did not fix the error. Your suggestion however did. Thanks!
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,258
Members
452,901
Latest member
LisaGo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top