Search TeachExcel.com
TeachExcel.com
TE
Teach Excel MS Office Tutorials Excel Consulting Services Excel Forum
Excel Video Tutorials Excel Tips Free Excel Macros Excel Help Resources Contact TeachExcel
Video Tutorials
  • Free Macros
  • Excel Help Directory
  • Excel 2007 Resources
  • Keyboard Shortcuts
  • Excel Forum
  • Contact/About

Macros
Excel Tutorials For Macros

Sort Data With Headers in Descending Order in Excel


Bookmark and Share

This Excel macro sorts data that has headers in descending order. This means that data is sorted Z to A and 10 to 1 - or reverse alphabetical order and highest to lowest. This macro also assumes that there is one row of headers at the top of your data set or data range. If you have more than one row of headers on your data, simply make the range reference to the entire table start one row below the top header row - this will take into account two rows for headers.

This is a great and simple sorting macro in Excel and will help to get you started or will fit nicely into existing macros that you have.

To use this macro, simply replace A1:C56 with the range reference of your entire data set or data table that you want to be sorted and then replace A1 with the cell reference of the row that you would like to sort the rest of the data by in descending order.
Where to install the macro:  Module

Excel Macro to Sort Data With Headers in Descending Order

Sub Sort_Descending_Basic_With_Header()
'Sorts a worksheet in descending order and assumes there are headers on the data

Range("A1:C56").Sort _
Key1:=Range("A1"), Order1:=xlDescending, Header:=xlYes

End Sub


Bookmark and Share


How to Install the Macro
  1. Select and copy the text from within the grey box above.

  2. Open the Microsoft Excel file in which you would like the Macro to function.

  3. Press "Alt + F11" - This will open the Visual Basic Editor - Works for all Excel Versions.  Or For other ways to get there, Click Here.

      For Excel Versions Prior to Excel 2007
      Go to Tools > Macros > Visual Basic Editor

      For Excel 2007
      Go to Office Button > Excel Options > Popular > Click Show Developer tab in the Ribbon. Then go to the Developer tab on the ribbon menu and on the far left Click Visual Basic

  4. On the new window that opens up, go to the left side where the vertical pane is located. Locate your Excel file; it will be called VBAProject (YOUR FILE'S NAME HERE) and click this.

  5. If the Macro goes in a Module, Click Here, otherwise continue to Step 8.

    1. Go to the menu at the top of the window and click Insert > Module
    2. Another window should have opened within the Visual Basic Editor's window. Within this new window, paste the macro code. Make sure to paste the code underneath the last line of anything else that is in the window.
    3. Go to Step 8.

  6. If the Macro goes in the Workbook or ThisWorkbook, Click Here, otherwise continue to Step 8.

    1. Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
    2. Then, at the bottom of the list that appears, double-click the ThisWorkbook text.
    3. A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
    4. Go to Step 8.

  7. If the Macro goes in the Worksheet Code, Click Here, otherwise continue to Step 8.

    1. Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
    2. Within the list that appears you will see every worksheet that is in that excel file. They will be listed as such: Sheet1(NAME OF SHEET HERE) and under that will be Sheet2(NAME OF SHEET HERE). Select the sheet in which you want the macro to run and double-click that sheet.
    3. A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
    4. Repeat steps b and c for every sheet you want the macro to work in. Putting the macro in one sheet will not enable it for any other sheets in the workbook.
    5. Go to Step 8.

  8. Close the Microsoft Visual Basic Editor window and save the Excel file. When you close the Visual Basic Editor window, the regular Excel window will not close.

  9. You are now ready to run the macro.



Similar Helpful Excel Resources

Macro To Sort Data In Descending Order - Excel

View Content
Is it possible to sort two different ranges of data on seperate tabs in descending order using a macro?

I would like sort data in both tabs by order of volume while keeping all data in tact. Also I do not want to include the header or "total" row in the sort.

Please refer to the .xls file for reference.

Thanks!

Sort In Descending Order - Excel

View Content

Ado Sort In Descending Order - Excel

View Content
Trying to figure out how to sort in Descending order.

Code:

    rst.Open "SELECT DISTINCT [" & str & "] FROM qry_Sol" & ComboBox3.Value & " ORDER BY [" & str & "] ;", cnn, adOpenStatic




Can You Sort A Chart Out In Ascending/descending Order - Excel

View Content
Please see attached doc.

The four macro buttons change the graph to show the specific month. Is there a way where i can sort the bars out so that the longest bar is at the top and the shortest at the bottom, or visa versa.

Like data sorting a table, but sorting the graph instead.

Thanks for your help...

One Macro To Sort Text In Ascending And Descending Order - Excel

View Content
Hi,

Is it possible to sort a range of data in ascending and descending order using just one macro? I can have two macros with the alternate choices on but I would really like just the one option.

I can do it if there is numerical data using this code:

Code:

Sub Sortcreation()
    Dim xlSort As XlSortOrder
     
    With Range("A4:IV23")
         
        If Range("A4") > Range("A5") Then
            xlSort = xlAscending
        Else
            xlSort = xlDescending
        End If
         
        .Sort Key1:=Range("A4"), Order1:=xlSort, Header:=xlNo, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal
    End With
     
End Sub


Any ideas?

Thank you in advance.

JP

Sort Autofilter List Items In Descending Order - Excel

View Content
Hi

I have a field which contains dates which are in "mmm-yy" format. The most recent dates appear at the bottom of the list.

how can i sort the list items within the autofilter drop down to appear in descending order?

Thanks

Vincent

Sort In Ascending Or Descending Order Based On Cell Value - Excel

View Content
Hi Guys,

I have a sheet, looking like that

product1
product2
product3
Total1

product1
product2
product3
Total2

product1
product2
Total3


What I want to achieve is if the total is positive, then sort the range above it in descending order, if the total is negative then sort t in ascending order, I would like that as a VBA since I need to execute after some other existing code

As in my simple example above I will have multiple range to sort, the cell with total are fixed so they can be 'hardcoded' in the vba, also the amount for the products can be positive or negative.

Thanks a lot!

Sort Autofilter List Items In Descending Order - Excel

View Content
Hi

I have a field which contains dates which are in "mmm-yy" format. The most recent dates appear at the bottom of the list.

how can i sort the list items within the autofilter drop down to appear in descending order?

If you can help then please post answers on the thread below:
http://excelforum.com/showthread.php...23#post1955323

Thanks

Vincent

Sort Pivot Table Fields In Ascending & Descending Order - Excel

View Content
Hi,

This one always seems to get me.

I have a pivot table setup like this -

I have 5 fields in my rows, and one field in my data section.

It is a simple employee pivot table -

The 5 rows are -

Department, Employee Name, Start Date, Term Date, Level and the data field is Salary.

I would like to sort the pivot table, so it shows -

The Department in Ascending order, than the Employee Names in Ascending Order, and then the salary (Data Field) in Descending order.

For some reason I can get it done.

Any help would be much appreciated.

Thanks,

Export Selected Rows To New Worksheet Then Sort In Descending Order - Excel

View Content
Hi all,

I am new to using macros and need some help. Currently using Excel 2007.

I have an Excel file that has many rows of data in columns A to G. Row 1 is the header row.

I need to be able to select x number of rows and put them in a separate worksheet in the same workbook with the header row.

Is it also possible to sort the new worksheet by Column C from Largest to Smallest?

I found the following script in another post:
http://excel.bigresource.com/Track/excel-gi1t3xnG/

However, it doesn't seem to save to another worksheet in the file.

Thanks,
Stan
Random Tutorials
Introduction to Making Formulas in Excel
(Easy)
IF Statement Introduction & Using Nested IF's
(Easy)
HLOOKUP() Function - Introduction
(Intermediate)
Absolute and Relative Cell References
   - & INDIRECT() Function Introduction

(Easy)
Consolidate & Combine Data from Separate Worksheets or Workbooks(Excel Files)
(Intermediate)
How to record a Macro - And what One is
(Easy)
Submit Inquiry Here
  • Prices From $10
Name:*
E-mail:*
Request:*
The macro(s) on this page will be sent with the request.
Contact | Privacy Policy | Disclaimer
Copyright© 2012 TeachExcel.com