You are here:

Excel/Macro to organize list in descending order

Advertisement


Question
I have a macro that Finds all the different manufacturers of a project in a table and adds up the total price each manufacturer accounts for in the project and puts it in a smaller table. So for example, the final, smaller table would say Microsoft in A1 and $500 in B1, and then Apple in A2 and $600 in B2, Dell in A3 $400 in B3 etc.

What I want to do is to write a macro that automatically organizes the table such that the Manufacturer with the greatest price is at the top of the list followed by the next highest all the way down to the lowest. I want to organize the table in descending order. ANy help would be greatly appreciated. thanks

Answer
Rico,

it would just be a sort of that region, with column B as the key field and choosing descending as the order

Sub SortData()
Dim r As Range
Set r = Range("A1").CurrentRegion.Resize(, 2)
r.Sort Key1:=Range("B1"), Order1:=xlDescending, Header:=xlNo
End Sub


If the data is all produced by formula, you might need to convert all the data to constants before you sort.

--
Regards,
Tom Ogilvy

About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

All Answers

Answers by Expert:


Ask Experts

Volunteer


Tom Ogilvy

Expertise

Worked with the program for many years - provided assistance on MS Excel Newsgroups since 1997. Have received the Microsoft MVP award annually since 1999. I don't answer questions on using Excel in a browser Since I have no way to test this. Prefer not to answer charting questions. I consider myself to be particularly knowledgeable about using VBA internal to Excel but have no problems with formulas and pivot tables either.

Experience

Have Used Excel for 15 - 20 years. Answered in excess of 70,000 Excel related questions in MS Excel newsgroups. Unless obvious, please specify whether you want a worksheet function or macro/VBA solution.

Education/Credentials
BS General Engineering (concentration in Industrial Engineering) MS Operations Research Systems Analysis

©2009 About.com, a part of The New York Times Company. All rights reserved.