Sort Routine Macro for Excel Worksheet

I have an excel that requires a sort routine.  I tried using the start/stop 
recording.  The code is shown below, however, I need this routine to work 
when you don't know how many rows are in the data.  My method has the 
filename hardcoded too.  I don't know if that matters.  This one subroutine 
of many.  Can someone show me how to make this routine more dynamic.  It 
will always sort by the same Column but it needs to work with all different 
Ranges of data (this example is hardcoded to sort data from row 2 through 
row 613.

Sub SortCategoryAssistance()
    Cells.Select
    ActiveWorkbook.Worksheets("NEEDWest Error Report").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("NEEDWest Error Report").Sort.SortFields.Add 
Key:= _
        Range("P2:P613"), SortOn:=xlSortOnValues, Order:=xlAscending, 
DataOption _
        :=xlSortNormal
    With ActiveWorkbook.Worksheets("NEEDWest Error Report").Sort
        .SetRange Range("A1:T613")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Range("A1").Select
End Sub
 

0
JCO
6/7/2010 5:31:30 PM
excel.programming 6508 articles. 2 followers. Follow

1 Replies
2255 Views

Similar Articles

[PageSpeed] 16

never mind.  I figured it out as shown below:
'
' SortCategoryAssistanceWithHeadersMacro
'
'
    Cells.Sort Key1:=Range("P2"), _
    Order1:=xlAscending, Header:=xlYes, OrderCustom:=1, _
    MatchCase:=False, Orientation:=xlTopToBottom
    '
    Range("A17").Select


"JCO" <someone@somewhere.com> wrote in message 
news:OHGNSHoBLHA.5584@TK2MSFTNGP06.phx.gbl...
> I have an excel that requires a sort routine.  I tried using the 
> start/stop recording.  The code is shown below, however, I need this 
> routine to work when you don't know how many rows are in the data.  My 
> method has the filename hardcoded too.  I don't know if that matters. 
> This one subroutine of many.  Can someone show me how to make this routine 
> more dynamic.  It will always sort by the same Column but it needs to work 
> with all different Ranges of data (this example is hardcoded to sort data 
> from row 2 through row 613.
>
> Sub SortCategoryAssistance()
>    Cells.Select
>    ActiveWorkbook.Worksheets("NEEDWest Error 
> Report").Sort.SortFields.Clear
>    ActiveWorkbook.Worksheets("NEEDWest Error Report").Sort.SortFields.Add 
> Key:= _
>        Range("P2:P613"), SortOn:=xlSortOnValues, Order:=xlAscending, 
> DataOption _
>        :=xlSortNormal
>    With ActiveWorkbook.Worksheets("NEEDWest Error Report").Sort
>        .SetRange Range("A1:T613")
>        .Header = xlYes
>        .MatchCase = False
>        .Orientation = xlTopToBottom
>        .SortMethod = xlPinYin
>        .Apply
>    End With
>    Range("A1").Select
> End Sub
>
> 
0
JCO
6/7/2010 9:25:06 PM
Reply:

Similar Artilces:

Excel as a database #3
is there any possibility that i used to print a invoice through excel for my product sale. is there any way excel can generate monthly sales book as a database. Please show me any path Thanks in advance. Rao Ratan Singh Rao, Consider Access for this project. To do this properly, you'll likely need a table for your products (your inventory or product line), one for your invoices, one for the items in your invoices, and if you're keeping customer information, one for your customers. Excel is terrific, but a lot of darn work to implement related tables, move records around, ...

Creating a print-macro that'll only print page 1?
Hi, I have a spreadsheet that contains multiple sheets. I want to add a button that runs a macro, which only prints page 1 on the first sheet (called Scorekort). The "Scorekort" sheet contains 13 pages in total, but I only want to print the first page. Any ideas for this macro? Anders hi, Sub Macro1() Sheets("Scorekort").PrintOut From:=1, To:=1, Copies:=1, Preview:=True, Collate:=True End Sub if you don't want a print preview, Preview:=False -- isabelle Le 2011-05-21 04:16, Anders M a �crit : > Hi, > > I have a spreadsheet that contains multiple ...

Forms & Worksheets
I want to create a form in word that will automatically add entered info into an excel worksheet? Is this possible Charlene, Setup you data in ordered columns, with headings in row 1, then menu Data>Form. -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "Charlene" <anonymous@discussions.microsoft.com> wrote in message news:A8A03DD4-85DB-4F80-B94A-C568FB95531E@microsoft.com... > I want to create a form in word that will automatically add entered info into an excel worksheet? Is th...

Problem with komma versus period in Excel
Hej I am have problems with the use of period in Excel. I Denmark komma is the decimal seperator. If I convert (from within VB Editor) the content of a cell from "6340,00" to text and replace the komma with period I get "6340" (I wanted "6340.00). If I make the convertion in Excel and record the macro at the same time I get the desired result i my sheet. BUT when I put in my code in VBA and run it from here I still get the wrong result, "6340" and not "6340.00". I know Excel (VBA) transform "." to "," probably acording to...

Flag a date in Excel
I wish to flag a date so that 10 days later, the input date will tur red so that I can follow it up. I have seen it done but don't know ho to do it. Please hel ----------------------------------------------- ~~ Message posted from http://www.ExcelTip.com ~~View and post usenet messages directly from http://www.ExcelForum.com Try using conditional formatting: Select the cell(s) Click Format > conditional formatting Put the settings "Under Condition 1" as : Formula Is | =TODAY()-A5>=10 Click Format button > Font tab > Color > Red > OK Click OK -- hth ...

Excell attachement do no shows up
I got an e-mail in Outlook from someone and it is supposed to have an attachement of something in Excel, but I don't see the attachment anywhere in the Outlook window, and I don't even know where to find the attachment to open it. I do have Office 2003, but never have used Excell. Any advise on how to find the attachemnt? Thanks in advance. Octavio, This question would be better asked in an Outlook newsgroup, not an Excel newsgroup. That said, are you sure that the sender actually attached the file? -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, ...

Excel shutting down when opening file
This is a follow up from a previous post. When opening a specific file with excel 2003, Excel will immediately shut down. When I re-open Excel it shows the file in the recovery box. When trying to recover the file it gives a message that file damage is too extensive to repair. I have no problem opening other Excel files. I also have Excel 2003 operating on three other computers and they do not have any problem opening the same file. I have started Excel in safe mode and tried to open the file but I get the same problem. I have started Windows XP in safe mode and then opened Exce...

Excel 2007; graph the best fit line from a regression analysis?
Try using this white space to ask you question with a bit more detail best wishes -- Bernard V Liengme Microsoft Excel MVP http://people.stfx.ca/bliengme remove caps from email "mattz" <mattz@discussions.microsoft.com> wrote in message news:574CCC66-72EA-44D0-8D36-2147B6C7C279@microsoft.com... > ...

store formula in macro then paste it when macro runs
I download a file every month and I need to format it adding columns, deleting rows, etc - also I need to add some formulas to the file so that the data is formatted according to my specifications and to be used in another model. The formula is to be pasted on cell B3 ... and the formula is =RIGHT(LEFT(A3,16),3). Thanks Is this what you need? Sub PasteFormula() Range("B3").Formula = "=RIGHT(LEFT(A3,16),3)" End Sub -- Cheers, Ryan "Nina" wrote: > I download a file every month and I need to format it adding columns...

Can I move Excel 2002 from my laptop to my desktop
My desktop has Excel 97 and I wish to have the same version on both computers. They are networked. You cannot 'move' Excel, or copy it. You have to install from the original CDs. If you don't have them you'd have to acquire them or you might be out of luck. -- Jim "X_Drive" <X_Drive@discussions.microsoft.com> wrote in message news:E1AA36E6-D7E2-4060-A661-1601C6879D41@microsoft.com... | My desktop has Excel 97 and I wish to have the same version on both | computers. They are networked. ...

Output query to excel 08-12-07
Hi, Can anyone help me with outputing the results of a query to a particular worksheet in an Excel workbook. Using an "Output To" macro, I've managed to output my query to Excel so that it replaces the whole .xls workbook. But what I need to do is output to Sheet 1 of the .xls workbook and leave Sheet 2 intact as it will have formulas referring to Sheet 1. Thanks Bob On Sun, 12 Aug 2007 21:52:07 +1000, Bob wrote: > Hi, > > Can anyone help me with outputing the results of a query to a particular > worksheet in an Excel workbook. > Using an "Output...

CSV in Word==>Excel....?
I have one field from a Word document that imports perfectly. Then, I have another field, separated by commas, that I would like to separate into different cells.....Is this possible? If so, how Thank you Matthew After you import the data, you could use Data>'Text to Columns' to separate the data. If it's not the last column in the imported data, move it temporarily, or insert sufficient blank columns to its right, to accommodate the split data. Matthew wrote: > I have one field from a Word document that imports perfectly. Then, I have another field, separated by comm...

A macro code to print multiple sheets in different w.books
Hi, i know i am not supposed to post the question twice, but could not get e reply on that forum. Sorry in advance. below is my question: Hi there, can anyone help me with the codes to get a macro to print local wbook sheets along with the several sheets in other workbooks? I was able to record a macro to print worksheets in the local workbook, but how do i make the same macro to print the worksheets in three more different workbooks with multiple worksheets in them? Thanks in advance? Have you tried recording a macro where you open the other books and print the appropriate sh...

Changing dates with a macro
I have a list of 7 dates, any Monday - Sunday, and I want to write a macro, that when run, will change the first date to 7 days in the future, and then have all the other dates respond to the change in the first date. I have taken an unused cell, and added 7 to the first date, but when i copy, or drag to the original cell, it either gives a #REF or the other cells wont respond. I write my macros by stepping through the processes. I don't know enough to actually write one using the visual basic language. A B C 1 8/30 Mon 2 +A1+1 =A2 ...

"Run" code causing macros to run twice and/or stopping
Hi - I have been building some macros that are to be run within other macros. Weird stuff was happening! I used the "Call" command instead of "Run." Everything finally worked perfect!! Being new to VBA I do not know the reason behind the "Run" command being different and causing my problems. BUT "call" sure is the answer to my recent irritations. After I got the darn things to finally work, I decided to do the responsible thing and use Option Explicit, which helped me clean up my code tremendously!! Hi, First, unless you have a reason to use...

Assigning Macros to Combo Box list
How do I assign separate macros to separate listings withing a combo drop down box? I am trying to create a combo drop down box that takes you to a specified sheet within the same workbook. I expect you don't. I've never done this, but it would seem to me that you read the value of the combo box and move to the correct sheet based on that value, probably using a Select Case statement in the code. On Mon, 11 Oct 2004 07:51:04 -0700, "eric" <eric@discussions.microsoft.com> wrote: >How do I assign separate macros to separate listings withing a combo drop >down...

Printing In Excel 12-01-09
I am sure I posted this but cant see it On-Line I have an Excel file that when i try and print it states 1 of 2368 Pages? The file is ok on another PC, would this be a virus or? Never seen this before and I am sure file is ok Thanks for any help Steve On Dec 1, 11:05=A0am, k11ngy <k11...@discussions.microsoft.com> wrote: > I am sure I posted this but cant see it On-Line > > I have an Excel file that when i try and print it states 1 of 2368 Pages?= =A0 > The file is ok on another PC, would this be a virus or? =A0Never seen thi= s > before and I am s...

Excel should allow you to change custom colours more easily
Dear Microsoft... With other office products you can change the custom colours very easily, with excel you have to go into tools, then options, then change the colours... Please make it as easy as the other office products. Thanks ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" in the ...

How do I view and edit the source code for a Chart in Excel 2003?
Is there a way to access the code (VBA?) for a Chart created in Excel 2003? I have generated a complicated Chart or graph which I want to then "Copy" and modify to make several more which access different spreadsheets. It is cumbersome to click in the Toggle box for the data ranges for X and Y. Instead, I was hoping there might be a way to use Search and Replace to change the text describing the data ranges. EBB Excel does not create VBA when creating a chart unless you have specifically recorded the steps of creating it (Tools>Macros>Record New Macro...). Even when y...

Using the Common Feed List in Excel
Is it possible to collect items from the Common Feed List (RSS feeds) generated by IE into Excel? I would like to screen a bunch of feeds from Craigslist and eBay and none of the readers I've tried seem to do it very well. TIA ed I have used the IE application with Excel to read 1000's of webpages. Depending on the Website it can be very simple, not so simple, or very complicated. Not all webpages are the same even though the make look similar. I don't know what you mean by "to do it very well". The code may not be simple. I would have to see the U...

Excel help please
How to add clip art in excel behind text & grid lines? I am trying to install Excel to my computer. On the box it does not indicate that Microsoft Office 2003 is necessary and I don't have Office 2003. Is that why I cannot install Excel? -- George "Anthony" wrote: > How to add clip art in excel behind text & grid lines? You should be able to install Excel as a stand-alone. -- HTH Bob Phillips (remove nothere from the email address if mailing direct) "george" <george8798@pacbell.net> wrote in message news:6367F467-57A8-442D-AEFF-D586744EC...

Excel 2007 03-10-10
Question: Can Excel arrange items in 'alpaphabetical' order all at once if items are all put into one column after a person is through inputting them? Or must everything be input in 'alphabetical' order? Thank you. Dave __________ Information from ESET NOD32 Antivirus, version of virus signature database 4932 (20100310) __________ The message was checked by ESET NOD32 Antivirus. http://www.eset.com Click Data, Sort David Dyke wrote: > Question: Can Excel arrange items in 'alpaphabetical' order all at once if > items are al...

Export Excel data to Access
I have an Excel wookbook template that I use to create new project files to track and manipulate data on individual projects. I also have an Access database where I record some common data as the spreadsheet resulting in duplicate data entry. How can I export data easily (i.e. novice programming experience)on a regular basis from these separate Excel files to a common Access table to eliminate this duplicate data entry? Thanks, Jim H. Jim, initiate the process from Access. Open your Access database and File > Get External Data > Import. Set Files of type to Microsoft Excel, then ...

Excel 2003 charting circular or spherical coordinates
Long time user of Excel, long time issue: Is there a way to plot (chart) using circular or spherical coordinates? I have Excel 2003. Scott - Go to the charting section of Stephen Bullen's web site: http://oaltd.co.uk/Excel/SBXLPage.asp#Charting and look for FunChrt6.zip, which shows how to use polar coordinates. - Jon ------- Jon Peltier, Microsoft Excel MVP Peltier Technical Services Tutorials and Custom Solutions http://PeltierTech.com/ _______ Scott @ Nordion wrote: > Long time user of Excel, long time issue: > Is there a way to plot (chart) using circular or spherical...

Deleting Rows with Macros
Starting at a specific cell, if the cell contents are less than or equal to zero ( or blank), then delete that row and the next three rows. After the deletion, if the now current cell's contents are still less than or equal to zero (or blank) then repeat, else if the now current cell's contents are greater than zero, then skip down four rows and repeat the process with that cell We used to be able to do this with LOTUS, but the macro no longer works in the latest version of EXCEL - the one difference was that LOTUS started from the bottom of the file and worked upwards - it's OK ...