LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Can I use a variable as a sort key in VB?

Hi,

I am trying to write a piece of code which will present users with an input
box (asking for a number) which will then select the current range and sort
it using the variable defined by the input box. How would I use the numeric
variable as the key to sorting my data.

Example:

mynumber = InputBox("Please enter the column number that you want the data
splitting by")
Range("A1").Select
ActiveCell.CurrentRegion.Select
Selection.Sort Key1:=mynumber, Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom

The problem must be around my storing a number as the variable but the sort
command would appear to want a string???

Please help...
 
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
Code for variable sort order Jacob Skaria Excel Discussion (Misc queries) 1 April 28th 10 02:26 PM
VBA Variable Range Sort Tony Excel Discussion (Misc queries) 4 April 9th 09 08:21 PM
Variable Column Sort Bernie New Users to Excel 1 December 29th 06 11:09 PM
How do I use a variable in a sort macro APealin Excel Worksheet Functions 0 October 12th 06 03:40 PM
Sort : how can I use a variable in a VB sort function? El Bee Excel Worksheet Functions 3 February 16th 06 09:34 PM


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