How do I use a variable in a sort macro

A

APealin

I have a macro which produces a number of tables, one under each othe
to show the sales statistics of a number of sales teams.

Because of the number of calculations involved the macro runs 1 team a
a time, copyies the values into a second worksheet, then calculates th
next team and copies the values under the first team and so on.

I need to add the ability to sort the tables (which an be of a varyin
number of rows) by a number of different headings.

The obvious and simple way is to simply write a macro for each sor
option which sorts the tables before it copies the values to the secon
worksheet.

However is there a way to add a variable as the sort key to determin
which field to sort by?

This is a section of the part of the macro. How do I determine the Ke
range. This does not work:

Sheets("Team 1").Activate
Range(Cells(10, 1), Cells(formulas, 84)).Select

Dim sortrange

sortrange = Worksheets("Full Report").Cells(3, 1).Value

Selection.Sort Key1:=Range(Cells(10, sortrange)), Order1:=xlDescending
Header:=xlGuess _
, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
_
DataOption1:=xlSortNormal

Range(Cells(10, 1), Cells(formulas, 84)).Copy
Sheets("Full Report").Activate
Cells(lines - 1, 1).Select

Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone
_
SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone
_
SkipBlanks:=False, Transpose:=Fals
 

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