Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default Macro to Sort

Thank you all for your help ..

Barb: your suggestion worked perfectly .. thanks heaps ..

Dave: Range("A13:Corner") is the range i want to sort. I just defined a name
'Corner' to cell DB50 as the range will change every time the user adds new
rows (or delete existing rows).

JLGWhiz: I tried your solution but for some reason the macro doesn't like
this "&" symbol! Everytime i run it, this symbol gets highlighted and i get
an error message "Type Mismatch" .. any idea why this happens?


"JLGWhiz" wrote:

If you are going to use Range() as your Sort Key then you would need to get
the column letter in the input box Like:

ColumnToSort = InputBox (€œPlease enter the index of the column you wish to
sort by€)
ColumnToSort = UCase(ColumnToSort)
SortKeyRange = ColumnToSort & 13
Selection.Sort Key1:=Range(SortKeyRange), Order1:=xlAscending,
Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

Otherwise, use the Cells configuration that Barb suggested. If you don't
want rows 1 thru 12 included in the sort, then you will need to define the
sort range as well. Otherwise, you can get undesired results.


If ColumnToSort = €œ€ then


"Tendresse" wrote:

Hi all,

I have a worksheet that has 106 columns, some of them have dates, some have
text, etc. I want to write a macro to allow users to sort the list in
ascending order based on the column of their choice, by asking the user to
enter the letter of the alphabet located on top of the column. Im using
excel 2003. I dont seem to get the code right yet. I would appreciate it if
someone tells me where I went wrong:

Sub SORT()

€˜ code that will select the range to be sorted

€˜ Ask user which column they want to sort by

Dim ColumnToSort as String

ColumnToSort = InputBox (€œPlease enter the index of the column you wish to
sort by€)

If ColumnToSort = €œ€ then
Exit Sub
End If

€˜Here is where Im stuck. I dont know how to use the ColumnToSort as the Key1
€˜I want Key1 to be the cell in Row number 13 and Column ColumnToSort

Selection.Sort Key1:=Range(ColumnToSort & 13), Order1:=xlAscending,
Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

End sub

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
Sort Macro BAKERSMAN Excel Discussion (Misc queries) 0 March 24th 10 05:34 AM
Sort Macro sross002 Excel Discussion (Misc queries) 4 April 23rd 09 02:46 PM
macro sort atv Excel Programming 1 March 28th 08 05:47 PM
Macro Help Needed - Excel 2007 - Print Macro with Auto Sort Gavin Excel Worksheet Functions 0 May 17th 07 01:20 PM
Using Macro to sort without clicking on macro button dd Excel Discussion (Misc queries) 3 May 3rd 07 06:00 PM


All times are GMT +1. The time now is 09:51 AM.

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"