Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1
Default How do I use a variable in a sort macro


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

Because of the number of calculations involved the macro runs 1 team at
a time, copyies the values into a second worksheet, then calculates the
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 varying
number of rows) by a number of different headings.

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

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

This is a section of the part of the macro. How do I determine the Key
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:=False




--
APealin
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to Sort automatically when file/save is selected KDG Excel Discussion (Misc queries) 3 December 20th 05 08:28 PM
dynamic sort macro across 3 linked sheets wrpalmer Excel Discussion (Misc queries) 0 December 11th 05 02:17 AM
Range used in a macro needs to be variable DaveP Excel Worksheet Functions 3 November 4th 05 03:23 PM
Closing File Error jcliquidtension Excel Discussion (Misc queries) 4 October 20th 05 12:22 PM
open file (as variable) from macro d chaps Excel Discussion (Misc queries) 1 March 14th 05 11:57 PM


All times are GMT +1. The time now is 12:44 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"