I'm am very new to using vba in excel and i'm trying to write a code that splits the names from one cell into 2 cells and leaves out the "," between the names and the middle initial
this is what i have so far but whenever i try to compile it highlight the first number Row = 2 and says "Compile error: Invalid outside procedure"
Does this mean i'm missing something?
I took a java class but a lot of the key words in vba are different
All my code
this is what i have so far but whenever i try to compile it highlight the first number Row = 2 and says "Compile error: Invalid outside procedure"
Does this mean i'm missing something?
I took a java class but a lot of the key words in vba are different
All my code
Code:
Dim Firstname As String
Dim Lastname As String
Dim x As Integer
Dim Row As Integer
Dim Col As Integer
Row = 2
Col = 1
Do While IsEmpty(ActiveCell.Offset(0, 1)) = False
x = InStr(2, Cells(Row, Col).Value, ",")
Lastname = Left(Cells(Row, Col).Value, x - 1)
Firstname = Mid(Cells(Row, Col).Value, Len(Cells(Row, Col).Value) - x - 1)
Cells(Row, Col + 1).Value = Firstname
Cells(Row, Col + 2).Value = Lastname
Row = Row + 1
Loop