From: Francisco on
On Excel 2003 it works perfectly, on Excel 2007 I have error 1004 "sort
method of range class failed".


Sub SortSalary(CellToSort As String, SortRange1 As String)
Sheets(1).Range(SortRange1).Sort Key1:=Range(CellToSort),
Order1:=xlAscending, Header:=xlYes
End if


Is it a bug on Excel 2007?
From: Francisco on
I made a typo when copying the code is "End Sub".

"Francisco" wrote:

> On Excel 2003 it works perfectly, on Excel 2007 I have error 1004 "sort
> method of range class failed".
>
>
> Sub SortSalary(CellToSort As String, SortRange1 As String)
> Sheets(1).Range(SortRange1).Sort Key1:=Range(CellToSort),
> Order1:=xlAscending, Header:=xlYes
> End if
>
>
> Is it a bug on Excel 2007?
From: Helmut Meukel on
The range in Key1 is not full qualified,
try this:
Sheets(1).Range(SortRange1).Sort _
Key1:=Sheets(1).Range(CellToSort), _
Order1:=xlAscending, Header:=xlYes

Helmut.

"Francisco" <Francisco(a)discussions.microsoft.com> schrieb im Newsbeitrag
news:92510636-E9BD-4631-A843-FA8C2CBFDDC8(a)microsoft.com...
> On Excel 2003 it works perfectly, on Excel 2007 I have error 1004 "sort
> method of range class failed".
>
>
> Sub SortSalary(CellToSort As String, SortRange1 As String)
> Sheets(1).Range(SortRange1).Sort Key1:=Range(CellToSort),
> Order1:=xlAscending, Header:=xlYes
> End if
>
>
> Is it a bug on Excel 2007?


From: Francisco on
Thanks, but it does not work.
I have sheet(1) as active sheet and it does work on Excel 2003, the problem
is Excel 2007.

"Helmut Meukel" wrote:

> The range in Key1 is not full qualified,
> try this:
> Sheets(1).Range(SortRange1).Sort _
> Key1:=Sheets(1).Range(CellToSort), _
> Order1:=xlAscending, Header:=xlYes
>
> Helmut.
>
> "Francisco" <Francisco(a)discussions.microsoft.com> schrieb im Newsbeitrag
> news:92510636-E9BD-4631-A843-FA8C2CBFDDC8(a)microsoft.com...
> > On Excel 2003 it works perfectly, on Excel 2007 I have error 1004 "sort
> > method of range class failed".
> >
> >
> > Sub SortSalary(CellToSort As String, SortRange1 As String)
> > Sheets(1).Range(SortRange1).Sort Key1:=Range(CellToSort),
> > Order1:=xlAscending, Header:=xlYes
> > End if
> >
> >
> > Is it a bug on Excel 2007?
>
>
> .
>
From: Rick Rothstein on
Your code, as posted originally, worked fine for me on my copy of XL2007. I
did not get any error when I tried it with headers in A1:G1, sample data in
A2:G10 and using this line to call your code...

SortSalary "C1", "A1:G10"

No errors were reported and the data sorted as expected.

--
Rick (MVP - Excel)



"Francisco" <Francisco(a)discussions.microsoft.com> wrote in message
news:20A5FA86-7B36-4186-87CF-786C62329332(a)microsoft.com...
> Thanks, but it does not work.
> I have sheet(1) as active sheet and it does work on Excel 2003, the
> problem
> is Excel 2007.
>
> "Helmut Meukel" wrote:
>
>> The range in Key1 is not full qualified,
>> try this:
>> Sheets(1).Range(SortRange1).Sort _
>> Key1:=Sheets(1).Range(CellToSort), _
>> Order1:=xlAscending, Header:=xlYes
>>
>> Helmut.
>>
>> "Francisco" <Francisco(a)discussions.microsoft.com> schrieb im Newsbeitrag
>> news:92510636-E9BD-4631-A843-FA8C2CBFDDC8(a)microsoft.com...
>> > On Excel 2003 it works perfectly, on Excel 2007 I have error 1004 "sort
>> > method of range class failed".
>> >
>> >
>> > Sub SortSalary(CellToSort As String, SortRange1 As String)
>> > Sheets(1).Range(SortRange1).Sort Key1:=Range(CellToSort),
>> > Order1:=xlAscending, Header:=xlYes
>> > End if
>> >
>> >
>> > Is it a bug on Excel 2007?
>>
>>
>> .
>>