#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 169
Default Combo Box

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




  #2   Report Post  
Posted to microsoft.public.excel.programming
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




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Combo Box

dim FoundCell as range
dim FindWhat as string

findwhat = "Client"

with worksheets("sheet1")
with .range("c9:AS9") 'what row has Client in it?
Set FoundCell = .Cells.Find(what:=FindWhat, after:=.cells(.cells.count), _
LookIn:=xlFormulas, lookat:=xlWhole, _
searchorder:=xlByRows, searchdirection:=xlNext)
end with

if foundcell is nothing then
'what do you do if Client can't be found?
else
.Range("C9:AS69").Sort Key1:=.cells(1,foundcell.column), _
Order1:=xlAscending, _
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
end if
end with

(I don't like xlGuess. If you know what it is, I think I'd specify.)




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



--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Combo Box

you're correct
use

dim colClient as long
colClient = 7 ' 7=G

Key1:=Cells(9,colClient)

you could easily use say the MATCH() function to determine what column to use
eg
colClient = worksheet.functions.Match(what,Range("A9:L9"),Fals e)

HTH
Patrick

"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




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 169
Default Combo Box

Thanks All- this is great

"Patrick Molloy" wrote:

you're correct
use

dim colClient as long
colClient = 7 ' 7=G

Key1:=Cells(9,colClient)

you could easily use say the MATCH() function to determine what column to use
eg
colClient = worksheet.functions.Match(what,Range("A9:L9"),Fals e)

HTH
Patrick

"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




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
linking a form combo box... results from the combo box to another Trey Excel Discussion (Misc queries) 1 July 15th 07 01:58 AM
combo reference on another combo box for picking address etc. kbjin Excel Worksheet Functions 1 December 8th 06 03:29 PM
"Combo Box - getting control combo box to stick in place in worksh ajr Excel Discussion (Misc queries) 1 February 16th 05 02:05 AM
"Combo Box - getting control combo box to stick in place in worksh ajr Excel Discussion (Misc queries) 0 February 15th 05 07:45 PM
Combo Box - Hide Combo Box w/Check Box Paul Excel Programming 5 December 3rd 04 10:58 PM


All times are GMT +1. The time now is 07:16 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"