I have an ActiveX Listbox and combobox on a worksheet. The combobox has values which represent the headers of the listbox.
When the combobox changes, a database (on a seperate sheet) sorts itself according to the combobox value and the listbox
should then change. Here's my code:
Private Sub cmbxSort_Change()
Sheets("pfactors").[c1] = Application.VLookup(cmbxSort.Value, Sheets("pfactors").[psorts], 2, False)
Selection.Sort Key1:=Range(Sheets("pfactors").Range("c1").Text), Order1:=xlAscending, Key2:=Range("C1") _
, Order2:=xlAscending, Header:=xlYes, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2 _
If you like these VB formatting tags please consider sponsoring the author in support of injured Royal Marines
pFactors contains the values for the combobox rowsource. C1 (the result of the lookup) will contain a cell value (A1,
B1, etc) which determines what column to sort by. AllParts is the dynamic range name of the database, which is stored on
Whenever I run this code, I get an error in the sorting section (also, if I don't use
Sheets("sheet2").select, excel can't seem to find the range.
Now, I created a userform with a listbox and a
combobox, doing the exact same thing, using the exact same code with the exception of the combox name. Everything else is
100% exact and it works like the gem.
What is up with the worksheet version that I'm missing?