Splitting Cell Contents

cabbagefoot

New Member
Joined
Jun 24, 2011
Messages
2
Hello

I am trying to split the contents of a cell which has a complete address in it:

Company name,
Address 2,
Address 3,
Address 4,
Post code

The below visual basic code which I found somewhere on this forum does a great job of splitting one cell (A4), however, is there any way to automatically change the cell reference so I can run the macro for A4, A5, A6,A7 in one go.........

Sub tst()
Dim X As Variant
X = Split(Range("A4").Value, ",")
Range("A4").Resize(UBound(X) - LBound(X) + 1).Value = Application.Transpose(X)
End Sub

Thanks in advance
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Hi and welcome to the board!!!
Untested, but give this a try
Code:
Sub tst()
Dim cl As Range
For Each cl In Selection
Dim X As Variant
X = Split(cl.Value, ",")
cl.Resize(UBound(X) - LBound(X) + 1).Value = Application.Transpose(X)
Next cl
End Sub

lenze
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,808
Members
452,944
Latest member
2558216095

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