I have been trying to write a macro to split a cell containing multiple names, by replacing specific characters with a special character that I can later use as a column delimiter. I hope this is clear enough and not too much trouble for someone to help out with. Thanks.
e.g. A1 contains “Smith, A, Jones, BTW, Brown, C, MacDonald, D, Benson, HK”
Using the following I can split off the first name by replacing the second comma
[VBA]Sub nameSplit ()
Do While ActiveCell <> ""
ActiveCell.Offset(0, 1).FormulaR1C1 =
WorksheetFunction.Substitute(ActiveCell.Offset(0, 0), ",", "|", 2)
ActiveCell.Offset(1, 0).Select
Loop
End Sub[/VBA]
I’ve tried many different options to make the multiple replacements, based on the following, but it only replaces the second target, ie, occurrence 6. I can’t make it perform one change, retain the change, stay in the cell, and perform a second.
.
[VBA]Sub AuSplit_1A()
Do While ActiveCell <> ""
With Selection.Interior
ActiveCell.Offset(0, 1).Formula = _
WorksheetFunction.Substitute(ActiveCell.Offset(0, 0), ",", "|", 4)
'ActiveCell.Select
'ActiveCell.Offset(0, 1).Formula = _
'WorksheetFunction.Substitute(ActiveCell.Offset(0, 0), ",", "|", 6)
End With
ActiveCell.Offset(1, 0).Select
Loop
End Sub[/VBA]