Hello,
I have names in Column A that are in this order "Jones, Ben" and I want the code to switch the name to say "Ben Jones" in Column B. I have the below VBA and I keep getting a Syntax Error message(see screen shot attached). I then want to AutoFill the formula in Column B to the last row of data in the worksheet. There typically won't be any blank rows in between the data but I included that just as a precaution.
I have names in Column A that are in this order "Jones, Ben" and I want the code to switch the name to say "Ben Jones" in Column B. I have the below VBA and I keep getting a Syntax Error message(see screen shot attached). I then want to AutoFill the formula in Column B to the last row of data in the worksheet. There typically won't be any blank rows in between the data but I included that just as a precaution.
VBA Code:
Sub Macro1()
Range("B1").Select
Dim last_row As Long
last_row = Cells(Rows.Count, 2).End(xlUp).Row
ActiveCell.Formula = "=RIGHT(A1,LEN(A1)-SEARCH(" ",A1))&" "&LEFT(A1,SEARCH(",",A1)-1)"
ActiveCell.AutoFill Destination:=Range(ActiveCell.Address & ":B" & last_row)
End Sub
Book1 | ||||
---|---|---|---|---|
A | B | |||
1 | Jones, Ben | Ben Jones | ||
2 | Johnson, Robert | |||
3 | Smith, Gary | |||
4 | ||||
5 | ||||
6 | ||||
7 | ||||
8 | ||||
9 | ||||
10 | ||||
11 | Jordan, Michael | |||
Sheet1 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
B1 | B1 | =RIGHT(A1,LEN(A1)-SEARCH(" ",A1))&" "&LEFT(A1,SEARCH(",",A1)-1) |