I am overall quite new to excel so any help is greatly appreciated, concerning my problem.
I download data from a vendor and the identifying data,(the first column), has an individual's name and their participant number in the same column separated by commas. The info is not in general format for excel, the cells are in text format. I will convert that afterward, but just thought I would mention it in case it matters for creating a proper vba macro.
The problem is the number of commas in the identifying data column is not always the same.
- sometimes a row has only participant number
- sometimes a row has last name, first name, participant number
- sometimes a row has name, participant number.
Participant number will always be last in the identifying column, there is just a variable number of commas before it because if an individual wants to be anonymous the name may not be there or only partially there.
What I am trying to do is separate it so that the participant number is in a separate column. The last name can be with the first name or it can be in its own column. It can be done either way. The names will change and the number of lines will change frequently but probably somewhere about 1000 rows every time I run this macro.
So data starts out looking like this:
I made this macro by using record macro in excel. Essentially I am adding two columns to the right of the identifying column and then doing a text to column feature to separate the data by commas. So the identifying data is put into three columns and then I rename the three columns.
Sub Add_and_rename_columns()
' Add_and_rename_columns Macro
'
Columns("B:B").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Columns("A:A").Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
:=Array(Array(1, 1), Array(2, 1)), TrailingMinusNumbers:=True
Range("A3").Select
ActiveCell.FormulaR1C1 = "Participant Last Name"
Range("B3").Select
ActiveCell.FormulaR1C1 = "Participant First Name"
Range("C3").Select
ActiveCell.FormulaR1C1 = "Participant Number"
End Sub
After macro I get this:
As you can see not all of the participant numbers are in the same column. Thanks for any help you can give.