Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default sorting named range

Thanks for your help

"Patrick Molloy" wrote in message
...
my table starts at D8 as width/depth not known

Option Explicit
Sub TestSort()
Dim RangeName As String
RangeName = "MySort"
With Range(Range("D8"), Range("D8").End(xlToRight).End(xlDown))
.Name = RangeName
End With
SortRange RangeName, 2
End Sub
Sub SortRange(WhichRange As String, col As Long)
Dim target As Range
Set target = Names.Item(WhichRange).RefersToRange
With target
.Sort .Cells(1, col), Header:=xlYes
End With
End Sub

This is a bit more generic in that the sort routine can be used several
times so sort differing ranges by other columns.

Can obviously be greatly enhanced but it is a demo

HTH
Patrick Molloy
Microsoft Excel MVP




"inquirer" wrote:

I have defined a named range in vba
srt = Cells(1, i).Value & "_sort"
ActiveWorkbook.Names.Add Name:=srt, RefersTo:=Range(Cells(2, 6),
Cells(lastrow, 6))
where lastrow is 45
How can I use the range to sort the data?
(The worksheet name is "Data")
I have tried
Selection.Sort Key1:=ActiveSheet.Name!srt, Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

but this gives me and Object required error.
Could someone give me the correct way to enter the named range in the
selection command please?
Thanks
CHris





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
Referencing a named range based upon Range name entry in cell Barb Reinhardt Excel Worksheet Functions 14 June 20th 07 07:19 PM
automatic range - named range give me circular reference... George Thorogood Excel Discussion (Misc queries) 0 February 22nd 07 07:53 PM
Array as a "named range" - formula ok in cells, but error as "named range" tskogstrom Excel Discussion (Misc queries) 11 December 28th 06 04:44 PM
inserting a named range into new cells based on a named cell Peter S. Excel Discussion (Misc queries) 1 June 4th 06 03:53 AM
Sorting lists of Named Ranges Daniel Magnus Bennét Björck Excel Programming 5 February 11th 04 10:02 AM


All times are GMT +1. The time now is 07:01 PM.

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

About Us

"It's about Microsoft Excel"