Code for splitting string at a specific character

kbishop94

Active Member
Joined
Dec 5, 2016
Messages
458
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
sorry for such a rudimentary question, but I just cant seem to get the right combination of mid/left/find in my code

What I'm trying to do is to take each string in column "L" (starting at L1 and ending with the last row found in that column) and at the " : " character, spilt the string with the number value going into the immediate column to the right ("M") and the string (less the spaces) going to the next column over from that (column "N".) Thanks in advance for any help!
1Capture.PNG
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Try this...
VBA Code:
Sub SplitToMN()

    Dim vA1, vA2
    
    With ActiveSheet
        vA1 = .Range("L1", .Cells(Rows.Count, "L").End(xlUp))
        ReDim vA2(1 To UBound(vA1), 1 To 2)
        For vN = 1 To UBound(vA1)
            vA2(vN, 1) = Split(vA1(vN, 1), ":")(0)
            vA2(vN, 2) = Trim(Split(vA1(vN, 1), ":")(1))
        Next vN
        .Range("M1").Resize(UBound(vA2), 2) = vA2
    End With
    
End Sub
 
Last edited:
Upvote 0
Solution

Forum statistics

Threads
1,214,944
Messages
6,122,391
Members
449,080
Latest member
Armadillos

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