Hi,
I am fairly new to vba and am currently stuck on what is probably a simple task. I have a set of addresses on a ssheet in one column but they are seperated by a return for each line of the address ie:
Jo Bloggs
One Street
Anytown
AnyCounty
I need to split the address into seperate columns for each line of the address (there are several hundred addresses)
I found this code which works perfectly fine when I select an address and click a button to run the sub:
But however I try to loop this it only ever works for the first address and then stops. I have tried looping for each cell in a selection, for each cell in a set range (For each cell in Range ("A2:A500")) and even leaving the working sub alone and using a second to Call the sub for each cell in the range, nothing seems to work.
Ideally I would like to select a range in the worksheet that contains the addresses, assign a macro to a button and have all addresses extract when button is clicked.
Any help greatly appreciated
I am fairly new to vba and am currently stuck on what is probably a simple task. I have a set of addresses on a ssheet in one column but they are seperated by a return for each line of the address ie:
Jo Bloggs
One Street
Anytown
AnyCounty
I need to split the address into seperate columns for each line of the address (there are several hundred addresses)
I found this code which works perfectly fine when I select an address and click a button to run the sub:
VBA Code:
[SIZE=3]Sub SplitText()
Dim str() As String
For Each c In ActiveCell.CurrentRegion.Cells
If Len(ActiveCell.Value) Then ' CHECK IF THE ACTIVE CELL IS NOT EMPTY.
' SPLIT THE ACTIVE CELL'S VALUE WITH LINE FEED (vbLf).
str = VBA.Split(ActiveCell.Value, vbLf)
' REARRANGE TEXT TO MULTIPLE COLUMNS.
ActiveCell.Resize(1, UBound(str) + 1).Offset(0, 1) = str
End If
Next
End Sub[/SIZE]
But however I try to loop this it only ever works for the first address and then stops. I have tried looping for each cell in a selection, for each cell in a set range (For each cell in Range ("A2:A500")) and even leaving the working sub alone and using a second to Call the sub for each cell in the range, nothing seems to work.
Ideally I would like to select a range in the worksheet that contains the addresses, assign a macro to a button and have all addresses extract when button is clicked.
Any help greatly appreciated