Sort macro error

  • Thread starter Thread starter sbitaxi
  • Start date Start date
S

sbitaxi

Can anyone help me with this? I keep getting a "Reference is not
valid" error 1004, and I can't figure out why. I've used the sort code
before and it worked fine. Now... No clue.

sKey is a reference to a cell, user picks the field from a drop down
and it enters the field value in the sKey source cell

LastRow is a function Ron de Bruin shared with me to find the last row
containing data

Ultimately, it is the segment for sorting that is "out of sorts".

Here's the code:

If sKey > 0 Then
DestSh.Select
Last = LastRow(DestSh)
Range("A4:AZ" & Last).Select

Selection.Sort key1:=sKey, Order1:=xlAscending, Header:=xlNo,
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Else
End If


Thank you!

Steven
 
key1 needs a range object.
Columns(sKey) or Range(sKey) may work, depending on what sKey returns.
--
Jim Cone
Portland, Oregon USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)


<[email protected]>
wrote in message
Can anyone help me with this? I keep getting a "Reference is not
valid" error 1004, and I can't figure out why. I've used the sort code
before and it worked fine. Now... No clue.

sKey is a reference to a cell, user picks the field from a drop down
and it enters the field value in the sKey source cell

LastRow is a function Ron de Bruin shared with me to find the last row
containing data

Ultimately, it is the segment for sorting that is "out of sorts".

Here's the code:

If sKey > 0 Then
DestSh.Select
Last = LastRow(DestSh)
Range("A4:AZ" & Last).Select

Selection.Sort key1:=sKey, Order1:=xlAscending, Header:=xlNo,
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Else
End If


Thank you!

Steven
 

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

Back
Top