Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel VBA ComboBox and Data Sort

Status
Not open for further replies.

robcunliffe

Technical User
Mar 22, 2005
22
GB
Hello

I am using office XP writting some VB for excel.

I have a fairly simple command that will sort data.

The user will click on a button to bring up a userform. The userform has a combo box. The combo box entries are cells (i.e. a5 , g5 etc) The user selects a cell they wish to sort on and click go.

Within the sub the datasort commands look like this (generated from a macro)

Range("A5:N5000").Select
Selection.Sort Key1:=Range(Cbosortby.Value), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Range("A6").Select


I ahve basically substituted the key1:=range()
for the cell the user selects in the combo box.

However i would like the combo box to contain entries like "UserID" or "Date" But i do not know what to put in the range bracket (above) so that it will sort the column.

For example the user selects "Date" from the combo box and the data is sorted for column A.

Can anyone help

Many Thanks

Rob Cunliffe
 
Have a look at named range.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top