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

Trying to sort a range A5:AZ350 on colum 'H' and then colum 'A' however I
would like to vary the first colum.
I created a macro to do the sort, but would like the macro to ask me what
colum to sort on when it runs , as the first colum varies all the time.
Any help appreciated

Roger


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default sorting a range

One way:

Option Explicit
Sub testme()

Dim myRng As Range
Dim myCol As Range

With Worksheets("sheet1")
.Select 'makes selecting the column easier
Set myRng = .Range("a5:az350")

Set myCol = Nothing
On Error Resume Next
Set myCol = Application.InputBox _
(prompt:="Please click on the column to use as the secondary key", _
Type:=8).Cells(1)
On Error GoTo 0

If myCol Is Nothing Then
'user hit cancel--just quit
Exit Sub
Else
If Intersect(myCol.Cells(1).EntireColumn, myRng) Is Nothing Then
'outside the range to sort, use H again
Set myCol = .Range("H1")
End If
End If

myRng.Sort key1:=.Range("h1"), order1:=xlAscending, _
key2:=myCol, order2:=xlAscending, _
header:=xlYes
End With

End Sub

I guessed at the orders and the headers.

hawk wrote:

Trying to sort a range A5:AZ350 on colum 'H' and then colum 'A' however I
would like to vary the first colum.
I created a macro to do the sort, but would like the macro to ask me what
colum to sort on when it runs , as the first colum varies all the time.
Any help appreciated

Roger


--

Dave Peterson
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
sorting range Jase Excel Discussion (Misc queries) 1 September 30th 08 06:42 PM
sorting range peyman Excel Discussion (Misc queries) 5 October 27th 07 10:29 PM
Sorting by range planetdust New Users to Excel 3 October 21st 07 01:03 AM
Sorting a Range cmm Excel Discussion (Misc queries) 1 June 30th 06 01:35 PM
Sorting Range Help HelpMe Excel Programming 4 January 8th 04 08:53 PM


All times are GMT +1. The time now is 09:06 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"