By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,405 Members | 1,357 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,405 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?



Thanks!!
Dec 26 '18 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 1,043
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

100+
P: 150
Luuk writes tips.
In your writing, I don't know what would go in column C, but I assumed that when "Published" was pressed, "P" would go in
Expand|Select|Wrap|Line Numbers
  1. Private Sub CommandButton1_Click()
  2. With ComboBox1
  3. Cells(.ListIndex + 2, 2).Value = "S"
  4. End With
  5. End Sub
  6.  
  7. Private Sub CommandButton2_Click()
  8. With ComboBox1
  9. Cells(.ListIndex + 2, 3).Value = "P"
  10. End With
  11. End Sub
  12.  
Dec 24 '19 #3

Post your reply

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