Writing Sort Code in 2007 that is 2003 Compatible

cicconmr

Board Regular
Joined
Jul 5, 2011
Messages
90
These are the two things I am trying:

Code:
        ThisWorkbook.Activate
ActiveWorkbook.Worksheets("Hardware").Range("A1:B501").Sort Key1:=Range("B2:B501"), Order1:=xlDescending, Header:=xlYes, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortValue


Code:
        ThisWorkbook.Activate
    With Sheets("Hardware")
        .Range("A1:B501").Sort _
        Key1:=Range("B2"), Order1:=xlAscending, Header:=xlYes
    End With

Neither works, I get a typical 1004 Error that says something to the effect of "The sort reference is not valid. Make sure that it's within the data you want to sort, and the first Sort By box isn't the same of blank."

Note: I have no problems in 2007, I also have no problems running the code on it's on, the only issue is when running it through Workbook_Open()

I'm really lost, I've seen similar problems on the internet but none of those solutions have helped....
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
You are missing a dot qualifier here:

Rich (BB code):
    With Sheets("Hardware")
        .Range("A1:B501").Sort _
            Key1:=.Range("B2"), Order1:=xlAscending, Header:=xlYes
    End With
 
Upvote 0
It looks to have worked, that was my error. Thanks very much, I'll be sure to hang on to that code so that 2003 users don't get the 1004 error, hope this helps others who are encountering that problem.
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,548
Members
452,927
Latest member
rows and columns

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