ravi4ever
Active Member
- Joined
- Apr 13, 2010
- Messages
- 316
I want this function with the help of VBA..
To Get First Name =LEFT(A2,FIND(" ",A2)-1)
To Get Last Name =RIGHT(A2,LEN(A2)-FIND(" ",A2))
A2 is the cell where Full Name is..
After googling I understood that we cannot WorksheetFunction but don't know why the below code isn't working.. please assist..
To Get First Name =LEFT(A2,FIND(" ",A2)-1)
To Get Last Name =RIGHT(A2,LEN(A2)-FIND(" ",A2))
A2 is the cell where Full Name is..
After googling I understood that we cannot WorksheetFunction but don't know why the below code isn't working.. please assist..
Code:
Dim LastRow As Long
Dim f As String
LastRow = Range("A1048576").End(xlUp).Row
For i = 2 To LastRow
If Cells(i, 1).Value <> "" Then
f = "=LEFT(A" & i & ")" & ",FIND(""""," & "A" & i & ")-1)"
Rng = "B" & i
Range(Rng).Value = f
Cells(i, 2) = f
Cells(i, 2).Value = f
End If
Next i