Sort Problem using a button

C

caldog

I have several worksheets, that I need to sort. My idea was to put a button
on what I call my 'input page' and sort each of these pages. But I get the
error: "Run-Time Error 1004: 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 or blank."

Now on sheet 1 is where the button is. Information that is to be sorted is
on sheet2, sheet3 sheet 4 and etc.

Sort code is:

Private Sub Sort1()

ActiveSheet.Range("A2:D14").Select
Selection.Sort Key1:=Range("A2"),Order:=xlAscending, Header:=xlNo,
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopTobottom,
DataOption1:=xlSortNormal

End Sub


Private Sub Main Button1()
'This is tied to main button on sheet 1
Sheets("Sheet 2").Select

Call Sort1

Sheets("Sheet 3").Select

Call Sort 1
End sub


Each range in each sheet will be the same. The error comes when I try to
call Sort1.

Can you folks give some help in letting me know what I am doing wrong.

Steve
 
M

michdenis

Hi,

Have you tried something like this ?


'-------------------
Sub Main_Button1()
For a = 2 To Worksheets.Count
Sort Worksheets(a)
Next
End Sub
'-------------------

Private Sub Sort(Sh As Worksheet)
With Sh
With .Range("A2:D14")
.Sort Key1:=.Item(1), Order1:=xlAscending, _
Header:=xlNo, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End With
End With
End Sub
'-------------------



"caldog" <[email protected]> a écrit dans le message de groupe de
discussion : (e-mail address removed)...
I have several worksheets, that I need to sort. My idea was to put a button
on what I call my 'input page' and sort each of these pages. But I get the
error: "Run-Time Error 1004: 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 or blank."

Now on sheet 1 is where the button is. Information that is to be sorted is
on sheet2, sheet3 sheet 4 and etc.

Sort code is:

Private Sub Sort1()

ActiveSheet.Range("A2:D14").Select
Selection.Sort Key1:=Range("A2"),Order:=xlAscending, Header:=xlNo,
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopTobottom,
DataOption1:=xlSortNormal

End Sub


Private Sub Main Button1()
'This is tied to main button on sheet 1
Sheets("Sheet 2").Select

Call Sort1

Sheets("Sheet 3").Select

Call Sort 1
End sub


Each range in each sheet will be the same. The error comes when I try to
call Sort1.

Can you folks give some help in letting me know what I am doing wrong.

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top