sorting problems for DA

D

Dean

I have a macro that is supposed to copy a list of things in a column from
one worksheet to another, then, after the pasting, it is to sort the
selection.

It works fine but, occasionally, the list is a list of only one item. And
if I then let it sort, since it doesn't see anything below the top of the
list, it grabs data that it sees in other adjacent columns, which I don't
want. Actually, if there is just one cell being sorted, there is no need to
sort! So, can someone modify my code below so that if the cells in the
column being pasted actually consists of only one cell, it will just skip
the sort. Here is what I have that needs to be modified:

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

Application.CutCopyMode = False

'IF SELECTION CONSISTS OF ONLY ONE CELL, SKIP THE SORT BELOW

Selection.Sort Key1:=ActiveCell, Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal


Thanks!
Dean
 
M

Mike Fogleman

If Selection.rows.count <3 Then
' do nothing
Else
Selection.Sort....

The count of <3 would include a header and 1 list item. If there is no
header in the selection then change to <2.

Mike F
 
D

Dean

That works, thanks, Mike.

Mike Fogleman said:
If Selection.rows.count <3 Then
' do nothing
Else
Selection.Sort....

The count of <3 would include a header and 1 list item. If there is no
header in the selection then change to <2.

Mike F
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top