Thread
:
Can I use a variable as a sort key in VB?
View Single Post
#
3
Posted to microsoft.public.excel.programming
Bob Phillips[_6_]
external usenet poster
Posts: 11,272
Can I use a variable as a sort key in VB?
Dim mynumber
mynumber = InputBox("Please enter the column number that you want the data
splitting by")
Range("A1").Select
ActiveCell.CurrentRegion.Select
Selection.Sort Key1:=Selection.Cells(1, CLng(mynumber)),
Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
--
HTH
RP
(remove nothere from the email address if mailing direct)
"Pablo Bellissimo" <Pablo
wrote in
message ...
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...
Reply With Quote
Bob Phillips[_6_]
View Public Profile
Find all posts by Bob Phillips[_6_]