![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Apr 2002
Posts: 9
|
I have a worksheet with several columns of data.
I have a macro that sorts the data by a field name (Cost). It works very well. However, sometimes I need to sort the same sheet by a different field name, like Date Orderd. Instead of having 2 or 3 different Macros, is there a way to modify my current Macro and have it ask me what field name to sort the worksheet by? A co-worker said he thought it could be done with an Input Box. |
|
|
|
|
|
#2 |
|
New Member
Join Date: Apr 2002
Posts: 9
|
This is what the macro looks like now.
It is very simple: Sub SortData2() ' ' SortData2 Macro ' Macro recorded 4/28/2002 by Jerry Russell ' ' Range("A8:G27").Select Selection.Sort Key1:=Range("A8"), Order1:=xlAscending, Header:=xlGuess, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom Range("A1").Select End Sub Thanks for any help. Jerry |
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Feb 2002
Location: Georgia USA
Posts: 544
|
Try this and see if it helps
Sub SortData2() ' ' SortData2 Macro ' Macro recorded 4/28/2002 by Jerry Russell ' Range("A8:G27").Select Selection.Application.Dialogs(xlDialogSort).Show Range("A1").Select End Sub |
|
|
|
|
|
#4 |
|
New Member
Join Date: Apr 2002
Posts: 9
|
This does work.
It prompts me with the Sort Dialoge Box and then finishes the Macro. I did get it to work a different way but I was having problems with validation. I posted a new question to see if anyone had any ideas. Can you help on that one too? Please check it out. Thanks, If the data validation question is not solved, I will use your solution! Jerry |
|
|
|
|
|
#5 |
|
Board Regular
Join Date: Feb 2002
Location: Georgia USA
Posts: 544
|
I thought that you would only have to pick the name of the column header from the list, validation would not be an issue, because only the column headers would be available to pick from and you would not have to type anything in, there by avoiding any possible mistakes
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|