Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 158
Default Sort macro error

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default Sort macro error


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)



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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
I tried to get around the problem of the pivot table field settingdefaulting to Count instead of Sum by running a macro of change the settingfrom Count to Sum. However, when I tried to run the Macro, I got error messageof run time error 1004, unable Enda80 Excel Worksheet Functions 1 May 3rd 08 02:35 PM
I tried to get around the problem of the pivot table field settingdefaulting to Count instead of Sum by running a macro of change the settingfrom Count to Sum. However, when I tried to run the Macro, I got error messageof run time error 1004, unable Enda80 Excel Discussion (Misc queries) 1 May 3rd 08 10:52 AM
Programed sort generates error: originated as recorded macro plh Excel Programming 2 October 31st 07 05:43 PM
Sort error jpas1954 Excel Discussion (Misc queries) 1 January 24th 07 04:24 PM
Macro / Sort error OniLink Excel Programming 4 March 5th 06 07:10 PM


All times are GMT +1. The time now is 08:40 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"