Range("A" & Rows.Count).End(xlUp).Row
That takes the last cell in column A (A65536 for me in 2003), then .end(xlup) is similar to pressing ctrl+up to move back to the last cell with data in and .row returns the row number.
Therefore:
Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)
Is the reference for column A from row 2 to the last row with data in and
For Each cl In Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)
steps through each cell in that range one at a time, assigning the variable cl to the cell
will split the string cl (the value of the cell) into an array of elements, delimited by spaces. The array will start at the index 0 and move up to the total number of elements. So for a string like "LastName Firstname" it would return:
"LastName" as element 0
and
"FirstName as element 1
refers to the first element of the created array (LastName) and
refers to the second element of the created array (FirstName)
Finally:
Left(Split(cl, " ")(1), 1)
The Left function takes the string in the first arguement and truncates it to the first n letters, where n is the second arguement. In our example it will therefore give the first letter of FirstName (F).
putting it all together you get:
Left(Split(cl, " ")(1), 1) & " " & Split(cl, " ")(0)
which gives
F & " " & LastName
which is
F LastName
and this is assigned to cl.value, which overwrites the current value, and then moves onto the next cell.
Bookmarks