Thread: Combo Box
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson[_3_] Jim Thomlinson[_3_] is offline
external usenet poster
 
Posts: 983
Default Combo Box

Here is some code for you It looks up the word "Client" in the range that you
want to sort, and then sorts that range by that column. If Client is not
found in the 9th row then an error message is posted... I hope this is what
you wanted...

Const strSortHeading As String = "Client"

Sub SortBy()
Dim rngSortColumn As Range
Dim rngToSort As Range
Dim wks As Worksheet

Set wks = ActiveSheet
Set rngToSort = wks.Range("C9:AS69")
Set rngSortColumn = Intersect(rngToSort, wks.Rows(9).Find(strSortHeading))

If rngSortColumn Is Nothing Then
MsgBox strSortHeading & " column not found", vbCritical, "Sort Error"
Else
rngToSort.Sort Key1:=rngSortColumn, Order1:=xlAscending, Header:=xlYes
End If
Set rngSortColumn = Nothing
Set wks = Nothing

End Sub

HTH

"teresa" wrote:

Sub SOR()
I have a combobox - when I choose an option it arranges data according to
Client which is currently in column G, however I need to sort data according
to "Client" irrespective of the Column, how do I tinker with the code below
to do this - Thanks

The bit I think I need changing is Key1:=Range("G9")
to
Range("col("Client")9) or something like this


Range("C9:AS69").Select
Selection.Sort Key1:=Range("G9"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub