PDA

View Full Version : [SOLVED] Running Macros from ComboBox with Items from a Range



sllaksvb
08-15-2017, 01:56 PM
Hi all,

I am relatively new to VBA and would require some help on a matter.

I am trying to run macros from the items in my combo box, and my combo box will be populated from a range on a different sheet (therefore the items in my combo box can change).

I am only familiar with calling macros using the exact values in the combo boxes, but seeing that the names change, I can not use the exact values.

My current code is:

Private Sub cmbaccdet_Change()
Select Case cmbaccdet.Value

Case "1"
Call FirstAccount
Case "2"
Call SecondAccount

End Select

End Sub


Is there something I can use to replace the 1 & 2 so that it calls the first and second option in the combo box without having to refer to them as "1" and "2"?

Thank you for your help!

YasserKhalil
08-15-2017, 02:19 PM
Hello
Can you upload sample of your workbook?

mdmackillop
08-15-2017, 02:26 PM
You could use ListIndex

Private Sub cmbaccdet_Click()
Select Case cmbaccdet.ListIndex
Case 0
Call FirstAccount
Case 1
Call SecondAccount
End Select
End Sub

sllaksvb
08-16-2017, 11:10 AM
Thank you! Exactly what I needed and works perfectly.