By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,827 Members | 1,967 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,827 IT Pros & Developers. It's quick & easy.

How do I link commandbuttons to combobox selection?

P: 1
Hi all,

I need to combine the action of a command button to be dependent on the selection in the Combo Box in order to fill the cell with the selection that the combo box refers to.

For instance, if I have three A columns,

A2: Shoes
A3: Socks
A4: Gloves

And two rows in B and C:

B1: Video
C1: Article

I have a userform where my command buttons are "Started" and "Published".

In my userform, the ComboBox lists Shoes, Socks, Gloves

Clicking Started or Published would place an "S" or a "P" in a cell. I want the cell that is filled with an S or P to be dependent on my ComboBox selection.

So if I choose Socks and clicked Started, an S would appear in B3. If I click Shoes in the ComboBox, then click the same Started command button, an "S" would appear in B2.

Do you know what coding I should use to make this happen, and if there's a shortcut or trick if I have a long list of columns?

Dec 26 '18 #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 1,022
Expand|Select|Wrap|Line Numbers
  1. Private Sub CommandButton1_Click()
  2.     a = "You clicked on " + UserForm1.ComboBox1.Value + "which is option number: " + Str(UserForm1.ComboBox1.ListIndex)
  3.     MsgBox a
  4. End Sub
the ListIndex starts counting from 0.
Dec 29 '18 #2

Post your reply

Sign in to post your reply or Sign up for a free account.