Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.setup
Paul
 
Posts: n/a
Default 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
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
Dynamic Range with unused formula messing up x axis on dynamic graph [email protected] Charts and Charting in Excel 2 February 2nd 06 08:02 PM
Help PLEASE! Not sure what answer is: Match? Index? Other? baz Excel Worksheet Functions 7 September 3rd 05 03:47 PM
Can I use named range in data range box when creating pie chart? BJackson Charts and Charting in Excel 2 August 17th 05 05:37 PM
Can a formula check for a certain value in a range? Lee IT Excel Discussion (Misc queries) 3 April 8th 05 07:36 AM
range and cells syntax mango Excel Worksheet Functions 0 February 22nd 05 12:03 AM


All times are GMT +1. The time now is 04:14 AM.

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"