Excel 2010:
I am using the Range.Sort method. When run, sometimes I get the following error:
Runtime error 1004: The sort reference is not valid. Make sure it is within the data you want to sort and the first sort by box isn't the same or blank.
Right now I am working with a static table so nothing is changing in it. Yet, VBA pops up with the error more often than not, especially if I run the macro from a button on a different sheet than the one being sorted.
The command it is having issues with is: Sheets("Data").Range("A1:B61").Sort Key1:=Range("B1"), Order1:=xlDescending, Header:=xlYes
The "Data" sheet is very simple. It has a column header called 'Name' (A1) and one called 'Score' (B1). Though the values under 'Name' do repeat often, that should not affect a Sort since I am sorting on 'Score' or B1. In the future, when my Data sheet is filled with thousands upon thousands of records, the Score values may repeat but a normal physical Sort done within Excel (not VBA) does not have an issue with duplicate values at all. So this error does not make sense.
The only thing that might be causing issues is when I am running the command from another sheet through a button. But since I explicitly tell it run the sort on the "Data" sheet it should not be having an issue. Frustrating!
Any suggestions would be appreciated.
Thx
I am using the Range.Sort method. When run, sometimes I get the following error:
Runtime error 1004: The sort reference is not valid. Make sure it is within the data you want to sort and the first sort by box isn't the same or blank.
Right now I am working with a static table so nothing is changing in it. Yet, VBA pops up with the error more often than not, especially if I run the macro from a button on a different sheet than the one being sorted.
The command it is having issues with is: Sheets("Data").Range("A1:B61").Sort Key1:=Range("B1"), Order1:=xlDescending, Header:=xlYes
The "Data" sheet is very simple. It has a column header called 'Name' (A1) and one called 'Score' (B1). Though the values under 'Name' do repeat often, that should not affect a Sort since I am sorting on 'Score' or B1. In the future, when my Data sheet is filled with thousands upon thousands of records, the Score values may repeat but a normal physical Sort done within Excel (not VBA) does not have an issue with duplicate values at all. So this error does not make sense.
The only thing that might be causing issues is when I am running the command from another sheet through a button. But since I explicitly tell it run the sort on the "Data" sheet it should not be having an issue. Frustrating!
Any suggestions would be appreciated.
Thx