VBA: Sorting problem. Cut Destination not working on multiple selections

musoguy

Board Regular
Joined
May 20, 2008
Messages
173
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:
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
Thanks in advance for any help,

James
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Solved it already! Realized the answer was in the question I had asked. I just did the sort before the code I pasted above which moved all the single names to the bottom of the list which meant there will only ever be one selection!
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top