Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.setup
|
|||
|
|||
Need help with creating a Range Name syntax
This lets a user select which columns to sort by:
A sort range is predefined. Row 1 is blank Now the user selects the columns to sort by: Within row 1, the user types a "1" in the column that s/he wants to sort by, a "2" in the second column to sort by, etc. My code is supposed to scan across row 1, locate the values "1" and "2", and plug them into the Sort Range value by creating Range names "ONE" and "TWO" at the cells where the "1" and "2" were found. But it crashes because I can't get the naming syntax right. Help is appreciated. Here's the code: Sub CREATE_SORT() Range("A1").Select ActiveWorkbook.Names("ONE").Delete ActiveWorkbook.Names("TWO").Delete For n = 1 To 50 'scan across row 1, looking for "1" or "2" Selection.Offset(0, 1).Select 'this is where I cant figure out how to name the selected cell If Selection.Value = 1 Then ActiveWorkbook.Names.Add Name:="ONE" Refers to XXXXX If Selection.Value = 2 Then ActiveWorkbook.Names.Add Name:="TWO" Refers to ZZZZZ Next n Range("A3:Z400").Select Selection.Sort Key1:=Range("ONE"), Order1:=xlAscending, Key2:=Range("TWO") _ , Order2:=xlAscending, Header:=xlNo, OrderCustom:=1, MatchCase:=False, _ Orientation:=xlTopToBottom End Sub TIA Paul |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Dynamic Range with unused formula messing up x axis on dynamic graph | Charts and Charting in Excel | |||
Help PLEASE! Not sure what answer is: Match? Index? Other? | Excel Worksheet Functions | |||
Can I use named range in data range box when creating pie chart? | Charts and Charting in Excel | |||
Can a formula check for a certain value in a range? | Excel Discussion (Misc queries) | |||
range and cells syntax | Excel Worksheet Functions |