Sort Problem using a button

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
0
Utf
1/11/2010 10:29:01 PM
excel.programming 6508 articles. 2 followers. Follow

1 Replies
607 Views

Similar Articles

[PageSpeed] 16

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" <caldog@discussions.microsoft.com> a écrit dans le message de groupe de 
discussion : 718A6DB5-718C-47AB-A057-B6B35B3340CD@microsoft.com...
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 

0
michdenis
1/11/2010 10:49:20 PM
Reply:

Similar Artilces:

OWA Problem (Again)
Dear fellow IT workers, If anyone experiencing the same problem as I have and has its solutions, sharing the knowledge, would be great appreciated. The problem as follows: When I access our-company OWA site and compose New Message, there is an error at the bottom-left of IE, "Error on page". In addition, I also cannot read the message using the preview-pane (at the right side) except by opening to a window. Either I cannot use 'Log-Off' button. This behaviour occurs if I access from the internet. But when I'm using Firefox, the 'New Message' button wor...

ADVANCE FILTER SORT
Hello! I have this form called "frm_FilterMain" with a button that execute this code "DoCmd.RunCommand acCmdAdvancedFilterSort" to open the advance filter sort fom named by access as "frm_FilterMainMain1 : Filter". After I completed selecting all the fields I wanted, key in all the cretirea, sort, etc then click the apply filter button this advance filter sort fom "frm_FilterMainMain1 : Filter" is still there and doesn't close. Is there any way to close this form as soon as my "frm_FilterMain" is displayed and active. Could anyone...

problem with MFC as statically linked lib
I'm writing a networking software........ and facing a weird problem. I have a worker thread in which I want a listening socket. At the point when the Create call is made on the socket...... I get an access violation error message from the debugger. This problem only occurs when I use MFC as a statically linked library............. when used as a shared dll, everything works well.......... I tried clicking through Doug Knox's website......... but I don't seem to find the solution there. Can anyone point me in the right direction or explain why I'm getting this error.. Than...

buttons to open new forms dont work
i made a form, added a button to open a new form in design view, went to form view, clicked the button doesnt work. i found out it doesnt work because i saved this access as a 2003 version when im using access 07. can any1 help me, & provide a SIMPLE ANSWER on how to fix this. Please dont say anything like, convert it into the 07 version because i have to use the 2003 version, CHEERS What do you get? an error message or the button doesn't work (no response) What is the code behind the OnClick event of the button? Check the OnClick event again, mybe the event was removed from ...

How do I connect the printer using the wirekess network (1010)
Dear Sir, I have recently aquired a network system using two computers. Th e first one has a 1250 Broadband connnectin and the second one works with s ten/ten wireless connection. I cannot get the printer to work off the second one. I have tried using the network set up wizard but this won't accept my name and password! HOW do I get t he blasted thing to WORK!!!!!!!!!!!!!! Looking forward to your reply. Yours sincerely, John Verney Wrong group. (Big time) -- JoAnn Paules MVP Microsoft [Publisher] "froggy702" <froggy702@discussions.microsoft.com> wrote in ...

Serious Outlook Problems
When I open Outlook 2000 I get the following error message. "An extension failed to initialize. Can't open file: C . The file may not exist, you may not have permission to open it, or it may be open in another program. Right-click the folder that contains the file, and then click Properties to check your permissions for the folder. You don't have appropriate permission to perform this operation." Now this is weird! It tells me what to do and then tells me I don't have permission to perform this operation???? I'm the only one on the computer! HOW DO...

how ,we can access function in c,by using thread in VC++
hi How ,we can use thread in VC++ so that we can access any function in c. Arbind I'm not sure this question is clear. Can you give more info? "Arbind" <arbindb_tech@rediffmail.com> wrote in message news:%23xHeb5PgDHA.908@tk2msftngp13.phx.gbl... > hi > > How ,we can use thread in VC++ so that we can access any function in c. > > Arbind > > You can use any thread in VC++/MFC to call any function, and that function can certainly be written in c. However, you must make sure that either all of the behavior of the function is completely t...

Sorting by Date (With a Twist)
A coworker gave me a list of data. One of the columns of this data was a date field formated custom in mm/dd/yyyy format. The problem was that when my coworker sorted the date field it was sorting by the day. No problem I thought, so I created a new column typed in =year(e2) which was the cell of the first date. To my suprise the data came back as 1905. The date in E2 was 5/16/2003. If I did =month(e2), I got January (in mmmm) format. What gives? -- B. Baumgartner ------------------------------------------------------------------------ B. Baumgartner's Profile: http://www.excelf...

What template does word use when creating emails for Outlook 2003
I want to be able to edit the .dot file that word uses to control the formatting when sending emails in Outlook 2003. What is it called and where can I find it please? Thanks rfc rfc <rfc at richardcooke.co.uk> wrote: > I want to be able to edit the .dot file that word uses to control the > formatting when sending emails in Outlook 2003. What is it called > and where can I find it please? My testing indicates that Outlook 2003 using Word for the editor uses Normal.dot for the template. -- Brian Tillman Thank you, I know at least in part this is correct. What wo...

Email bugs when using Publisher to send an email
I design art gallery invitations with Publisher but when I send what looks to be a perfectly sorted publisher file that has no 'Design Checker' issues, the resulting email has little problems. These could be fragmented outline borders applied to an image or random spaces between images and text - but none of these exist on the publisher document itself! I have sent my emails to webmail and client-based email addresses and tried different images but I still get the same problems! Are these just bugs that I have to live with? Thanks for this Charles. However, when Publisher ...

Problem with date base units for x axis
The problem is that if you have dates as the X-axis series for a chart, the only options for Base Units are Days, Months or Years. If you have quarterly data, excel adds extra space between the data points. A simple example illustrates the problem: Create a column chart from the following data Quarter Value 31-Mar-04 3 30-Jun-04 6 30-Sep-04 9 31-Dec-04 12 Note that the dates to appear on the X axis are the end of each quarter (every 3rd month) Create a simple Column chart from the data. Right-click on the data series and choose Format Data Series, O...

Problem with Update Trigger
SQL2008 I have two databases, both with identical tables ( apart from TableNames ). I have tried putting an update trigger on DB1.tbCBMOAccount to update the field country on DB2.tbBOSS_OAccount with the updated value from DB1.tbCBMOAccount ALTER TRIGGER [dbo].[trig_UpdateOriginatongAccounts] ON [DB1].[dbo].[tbCBMOAccount] AFTER UPDATE AS BEGIN Declare @OAccountID UniqueIdentifier Declare @Country varchar(32) Select @OAccountID = OAccountID , @Country = Country From Inserted IF UPDATE(Country) BEGIN UPDATE DB2.dbo.tbBOSS_OAccount SET Country = @Country ...

DCount problem 03-30-07
I am using the following for a form's textbox controlSource: =DCount("[DRef]","[q1Main]",("[q1Main.DRef]">=#06/01/02# And "[q1Main.DRef]"<=#06/30/06#) And "[q1Main.CaseType]"="CUS") The count is 0, but I know the count should be larger than 0. Does anyone see something goofy in my code? TIA Your quotes are wrong. =DCount("[DRef]","[q1Main]",("[q1Main.DRef]>=#06/01/02# And [q1Main.DRef]<=#06/30/06#) And [q1Main.CaseType]='CUS'") (that's And [q1Main.CaseType]= ' C...

Advanced button in Properties dialog box
Hi, When I click on the "Advanced..." button in the Properties dialog box for my main outlook.pst folder in Outlook I get the following error: "The operation failed. An object cannot be found". I am running Outlook 2003 with BCM. When I try to click Advanced for another smaller pst file, it works, but it is in Outlook 97-2002 format. I need to get to the advanced section to initiate the Compact function after archiving my 2004 emails. Worst case is I have to leave the computer idle for a while and let it compact automatically. Any help on how to fix this would be app...

Multitable query problem
Hey. I have a problem I can't wrap my head around. I have a database with mostly normalized data. I have a few tables with a common key, so they are no problem TBL_Tag *tagno description area etc... TBL_Tag_Termination *Tagno misc tag info... TBL_Tag_Misc *Tagno misc tag info fields... Then I have a list of users that log on, and by doing that I set a public variable 'Login' that is the userID. I retrieve this number in my forms and queries by the function Getlogin(). All of this works. Now, to my problem: I have a table that link users to areas: ...

Row Autofit Problem
I have a spreadsheet with many cells containing multiple lines of text. I've formatted all of them to autofit the row height, but some cells refuse to autofit, and display the text as ######### regardless of how I adjust the row height, even manually. I have no merged cells. In other cells (also formatted to autofit), the text is showing, but only a few lines--again, the row height refuses to adjust. Gord, Thanks, the general format tip seemed to work. -p "Gord Dibben" wrote: > Peter > > Try formatting the cells as General. Excel has problems with text-f...

Linking problem #3
Thanks everyone. Re where I had the links pointing they are to externa sheets and there are no similar formulas within the master sheet, s cannot make them 'point to themselves'. The Edit Replace has no worked, but will try the downloadable zip file and see how we go! Bil -- daniso ----------------------------------------------------------------------- danison's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1009 View this thread: http://www.excelforum.com/showthread.php?threadid=27352 ...

does anyone here actually use names?
hi, i am self learning about excel. i have came across NAMES topic. does anyone here actually use names? when r they usefull? i dont reall see a real need for them, especially in formulas. the only time i use name is for when i name a large block of data, so dont have to re-select the cells all the time. cheer -- Message posted from http://www.ExcelForum.com There are lot's of uses for named range and named constants etc. See the 2 links below http://www.ozgrid.com/Excel/DynamicRanges.htm http://www.ozgrid.com/News/excel-named-ranges.htm#ExcelTips Posted via: http://www.ozgrid....

Problem when exporting data from mscrm
Hi, I have built an expression using the advanced tool and then ordered the results by one of the displayed columns. However, when I try to export the results to excel there is a difference between the advanced find results and what actually gets exported to excel! Has anyone else experienced this? Thanks Lee ...

Using Vlookup in chart form
I have a spreadsheet project for my computer class....and I need help on using Vlookup on a chart. The Chart is as follows: Credit Score Area Code 300 400 500 114 3% 4% 5% 113 112 You get the idea....anyways, basically what I'm trying to do is get the %(which will be a discount %) that matches the credit score and area code. I know I need to use Vlookup, but I'm having trouble getting it to work. Do i need to use more than one lookup formula all in one??? ...

useful links
Hello everybody, Would you like to visit my website? Thank you. http://www.geocities.com/iozce ...

need HELP IN XML USING VB.NET
hi all i have a doubt! i want to compare two files,one is a xml file which has some certain rules,and the otherone is a "c" file. i want to check each and every line of the "c" file which should satisfy the rules written in xml file,if any error occurs,it should display an error message in a new window (Or msgbox) i want to do it with visual basic.net. is any ONE OF U KNOW HOW TO DO THIS? IF SO PLEASE SEND ME THE CODE TO svprajesh@yahoo.com thank you, rajesh. ...

Outlook 2000 to 2003: Using old pst file
I recently bought a new computer and have installed Office 2003. I think I must have started Outlook and created a personal data file before copying the pst file from my old version of Outlook (I think 2000) into the Outlook 2003 folder. In any event, I have two Personal Folders in Outlook 2003. Following instructions regarding using old pst files ("Reconnect your old Outlook data file" located at http://office.microsoft.com/assistance/preview.aspx? AssetID=HA010771141033&CTT=98), I have tried renaming the old pst file by right-clicking its Personal Folder icon, going t...

Do not print a button when print
I have a button on a worksheet and sometime ago I have set/written code to hide the button when printing. I forget I set the property or by macro. In 'Design Mode', right click your button, and Select 'Properties' from the context menu, in the properties dialog you will find a property called 'PrintObject', set this to either Yes or No depending on your preference. HTH Neil www.nwarwick.co.uk "Man Utd" wrote: > I have a button on a worksheet and sometime ago I have set/written code to > hide the button when printing. > I forget I set the prop...

Using Outlook'98 to manage files performs illegal operation #2
2nd Posting, still know answer, please help. If anyone has ol98, please try to duplicate. I setup the outlook bar w/ shortcuts to different folders (local & network) so that I could use it instead of windows explorer. The first time I set this up, it worked fine for a couple of days, and now all I get is illegal operations when I click on one of the short cuts. OUTLOOK caused an invalid page fault in module KERNEL32.DLL at 015f:bff9d709. Any suggestions? ezroller ...