Macro to separate 1 column into multiple columns

dac1517

Board Regular
Joined
Sep 20, 2010
Messages
103
In column BN I have data in the format 1000A-01-100. I would like to separate this into 3 columns using the "-" as the point of separation. Below is the code I found on the forums that I tried to use for this but I keep getting a runtime error "1004".

Code:
Sub SplitBrokerData()
 
    Dim arr As Variant, i As Long
 
    For i = 1 To Range("BN1").End(xlDown).Row
        arr = Split(Cells(i, 1), "-")
        Cells(i, 2).Resize(, UBound(arr) + 1) = arr
    Next
 
End Sub

Any help would be appreciated
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Try this code
Code:
Sub SplitIt()
Dim MyArr As Variant, LR As Long, c As Range
LR = Range("BN" & Rows.Count).End(xlUp).Row
For Each c In Range("BN1:BN" & LR)
    MyArr = Split(c, "-")
    For i = LBound(MyArr) To UBound(MyArr)
        c.Offset(, i + 1).Value = MyArr(i)
    Next i
Next c

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,594
Messages
6,179,794
Members
452,943
Latest member
Newbie4296

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