I am trying to use VBA to sort a list of names by Last Name, where each full name is in Column B. I have figured out how to extract the First Names to Column P and the Last Names to Column Q. However when I sort them by Column Q, if a person only has a First Name listed they go to the bottom of the list as the Last Name cell is blank. I have tried to fix this by finding blank cells in range Q2:Q100 and then copying across the value from row P, but I am getting an error that the Cut Destination command I am using cannot be performed with multiple selections. Is there another way round sorting the data, or to fix the coding issue? I have a feeling it may involve a loop, and I have not got my head around them yet!
Current code is below:
Thanks in advance for any help,
James
Current code is below:
Code:
'The following seperates the full names into First and Last Name columns (P & Q) - Works
With Range("B2:B100")
.TextToColumns Destination:=Range("P2"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=True, Other:=False, FieldInfo _
:=Array(Array(1, 2), Array(2, 1)), TrailingMinusNumbers:=True
End With
'Selects blank cells in Column Q - Works
With Range("Q2:Q100")
.SpecialCells(xlBlanks).Select
End With
'Meant to cut and paste the cell to the left of a blank cell into the blank cell - Doesn't work
With Selection.Offset(0, -1)
.Cut Destination:=Selection
End With
James