TAPS_MikeDion
Well-known Member
- Joined
- Aug 14, 2009
- Messages
- 622
- Office Version
- 2011
- Platform
- MacOS
Hi all,
I have three (3) button in a Group:
Group Name:
Sorting
Button Names:
FirstNameSortButton
LastNameSortButton
LocationSortButton
Since a ComboBox cannot show more than 1 column when the "ComboBox1_Change()" event fires, I had to overlay a 2 column ListBox on top of my ComboBox so all 3 columns of info can be shown (i.e. Last Name, First Name, Location.)
Depending on which button in the Group is selected will depend on what order the data is placed into the 3 columns (Column 1 = ComboBox, and Columns 2 & 3 = ListBox.) In a nutshell, I just want the "ComboBox1_Change()" event to display the three columns like it does when the "ComboBox1_Click()" event fires.
Hopefully someone can assist, and hopefully I didn't lose you with what I need to accomplish.
Here's what I was trying, but the "Application.Caller" (something I came across in a search) doesn't like my code. I get a Type Mismatch in the Case clause, and I'm not even sure if I can run a Select Case statement within a With statement since the Run-Time Error stopped the code at the type mismatch.
As always, thank you!
I have three (3) button in a Group:
Group Name:
Sorting
Button Names:
FirstNameSortButton
LastNameSortButton
LocationSortButton
Since a ComboBox cannot show more than 1 column when the "ComboBox1_Change()" event fires, I had to overlay a 2 column ListBox on top of my ComboBox so all 3 columns of info can be shown (i.e. Last Name, First Name, Location.)
Depending on which button in the Group is selected will depend on what order the data is placed into the 3 columns (Column 1 = ComboBox, and Columns 2 & 3 = ListBox.) In a nutshell, I just want the "ComboBox1_Change()" event to display the three columns like it does when the "ComboBox1_Click()" event fires.
Hopefully someone can assist, and hopefully I didn't lose you with what I need to accomplish.
Here's what I was trying, but the "Application.Caller" (something I came across in a search) doesn't like my code. I get a Type Mismatch in the Case clause, and I'm not even sure if I can run a Select Case statement within a With statement since the Run-Time Error stopped the code at the type mismatch.
Code:
Private Sub ComboBox1_Change()
Dim SelectedRow As Long
Dim sbSelected As Long
Dim ws As Worksheet
Set ws = Sheets("DataSheet")
SelectedRow = Me.ComboBox1.ListIndex + 2
Select Case Application.Caller
Case FirstNameSortButton
sbSelected = 1
Case LastNameSortButton
sbSelected = 2
Case LocationSortButton
sbSelected = 3
End Select
With Me.ListBox1
.Clear
.ColumnHeads = False
.ColumnCount = 2
.ColumnWidths = "186;186"
.Font.Size = 14
Select Case sbSelected
Case 1
'FirstNameButton selected
'Show Last Name & Location
.AddItem ""
.List(0, 0) = ws.Cells(SelectedRow, 2)
.AddItem ""
.List(0, 1) = ws.Cells(SelectedRow, 28)
Case 2
'LastNameButton selected
'Show First Name & Location
.AddItem ""
.List(0, 0) = ws.Cells(SelectedRow, 3)
.AddItem ""
.List(0, 1) = ws.Cells(SelectedRow, 28)
Case 3
'LocationButton selected
'Show First Name & Last Name
.AddItem ""
.List(0, 0) = ws.Cells(SelectedRow, 3)
.AddItem ""
.List(0, 1) = ws.Cells(SelectedRow, 2)
End Select
End With
End Sub
As always, thank you!
Last edited: