PC Review


Reply
Thread Tools Rate Thread

Button Sort Macro Not Working

 
 
=?Utf-8?B?VG9ueUQ=?=
Guest
Posts: n/a
 
      26th Feb 2007
I have a button macro that opon a worksheet(01-Length of Contract-Rollovers),
selects the sort area(Data), then sort by three criteria(K7, B7, A7). As I
record the macro to do the job it goes smoothly. As soon as I run the
recorded macro or attaches it to a button, it gives me a "Run-time error
'1004'" errorthat states "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."

Sheets("01-Length of Contract-Rollovers").Select
Application.Goto Reference:="Data"
Selection.Sort Key1:=Range("K7"), Order1:=xlDescending, Key2:=Range("B7") _
, Order2:=xlAscending, Key3:=Range("A7"), Order3:=xlAscending, Header _
:=xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom _
, DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
xlSortNormal

 
Reply With Quote
 
 
 
 
Don Guillett
Guest
Posts: n/a
 
      26th Feb 2007
You went to data( rename to MYdata) but you didn't select it. Try this IDEA
from anywhere in the workbook. Notice the placement of the dots . in
front of .range .

Sub gotomydata()
With Sheets("yoursheet")
.Range("mydata").Sort Key1:=.Range("a2")
End With
End Sub

--
Don Guillett
SalesAid Software
(E-Mail Removed)
"TonyD" <(E-Mail Removed)> wrote in message
news:50DFDC14-7B1C-42C0-AE4D-(E-Mail Removed)...
>I have a button macro that opon a worksheet(01-Length of
>Contract-Rollovers),
> selects the sort area(Data), then sort by three criteria(K7, B7, A7). As I
> record the macro to do the job it goes smoothly. As soon as I run the
> recorded macro or attaches it to a button, it gives me a "Run-time error
> '1004'" errorthat states "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."
>
> Sheets("01-Length of Contract-Rollovers").Select
> Application.Goto Reference:="Data"
> Selection.Sort Key1:=Range("K7"), Order1:=xlDescending, Key2:=Range("B7")
> _
> , Order2:=xlAscending, Key3:=Range("A7"), Order3:=xlAscending, Header
> _
> :=xlGuess, OrderCustom:=1, MatchCase:=False,
> Orientation:=xlTopToBottom _
> , DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:=
> _
> xlSortNormal
>



 
Reply With Quote
 
=?Utf-8?B?VG9ueUQ=?=
Guest
Posts: n/a
 
      26th Feb 2007
So far so good. How can I add extra search criteria?

"Don Guillett" wrote:

> You went to data( rename to MYdata) but you didn't select it. Try this IDEA
> from anywhere in the workbook. Notice the placement of the dots . in
> front of .range .
>
> Sub gotomydata()
> With Sheets("yoursheet")
> .Range("mydata").Sort Key1:=.Range("a2")
> End With
> End Sub
>
> --
> Don Guillett
> SalesAid Software
> (E-Mail Removed)
> "TonyD" <(E-Mail Removed)> wrote in message
> news:50DFDC14-7B1C-42C0-AE4D-(E-Mail Removed)...
> >I have a button macro that opon a worksheet(01-Length of
> >Contract-Rollovers),
> > selects the sort area(Data), then sort by three criteria(K7, B7, A7). As I
> > record the macro to do the job it goes smoothly. As soon as I run the
> > recorded macro or attaches it to a button, it gives me a "Run-time error
> > '1004'" errorthat states "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."
> >
> > Sheets("01-Length of Contract-Rollovers").Select
> > Application.Goto Reference:="Data"
> > Selection.Sort Key1:=Range("K7"), Order1:=xlDescending, Key2:=Range("B7")
> > _
> > , Order2:=xlAscending, Key3:=Range("A7"), Order3:=xlAscending, Header
> > _
> > :=xlGuess, OrderCustom:=1, MatchCase:=False,
> > Orientation:=xlTopToBottom _
> > , DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:=
> > _
> > xlSortNormal
> >

>
>
>

 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      26th Feb 2007
What I gave was an example. "Extra SEARCH criteria"? If you meant extra SORT
criteria just do it the same way with the dot in front of range.



--
Don Guillett
SalesAid Software
(E-Mail Removed)
"TonyD" <(E-Mail Removed)> wrote in message
news:491F9C4E-2509-47E9-A696-(E-Mail Removed)...
> So far so good. How can I add extra search criteria?
>
> "Don Guillett" wrote:
>
>> You went to data( rename to MYdata) but you didn't select it. Try this
>> IDEA
>> from anywhere in the workbook. Notice the placement of the dots .
>> in
>> front of .range .
>>
>> Sub gotomydata()
>> With Sheets("yoursheet")
>> .Range("mydata").Sort Key1:=.Range("a2")
>> End With
>> End Sub
>>
>> --
>> Don Guillett
>> SalesAid Software
>> (E-Mail Removed)
>> "TonyD" <(E-Mail Removed)> wrote in message
>> news:50DFDC14-7B1C-42C0-AE4D-(E-Mail Removed)...
>> >I have a button macro that opon a worksheet(01-Length of
>> >Contract-Rollovers),
>> > selects the sort area(Data), then sort by three criteria(K7, B7, A7).
>> > As I
>> > record the macro to do the job it goes smoothly. As soon as I run the
>> > recorded macro or attaches it to a button, it gives me a "Run-time
>> > error
>> > '1004'" errorthat states "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."
>> >
>> > Sheets("01-Length of Contract-Rollovers").Select
>> > Application.Goto Reference:="Data"
>> > Selection.Sort Key1:=Range("K7"), Order1:=xlDescending,
>> > Key2:=Range("B7")
>> > _
>> > , Order2:=xlAscending, Key3:=Range("A7"), Order3:=xlAscending,
>> > Header
>> > _
>> > :=xlGuess, OrderCustom:=1, MatchCase:=False,
>> > Orientation:=xlTopToBottom _
>> > , DataOption1:=xlSortNormal, DataOption2:=xlSortNormal,
>> > DataOption3:=
>> > _
>> > xlSortNormal
>> >

>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro Button to Sort Columns - Troubleshooting ideas? Munchkin Microsoft Excel Programming 1 1st Jun 2009 11:37 PM
Using Macro to sort without clicking on macro button dd Microsoft Excel Misc 3 3rd May 2007 06:00 PM
Re: sort button,macro, or ? Richard Buttrey Microsoft Excel Programming 0 27th Aug 2005 05:52 PM
Macro w/filter, copy, paste,& sort isn't working consistently kildevil Microsoft Excel Programming 3 19th Feb 2004 05:01 AM
Macro button stops working when macro moved HONYAKUKA Microsoft Word Document Management 1 13th Jul 2003 09:28 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:46 PM.