470,575 Members | 1,860 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,575 developers. It's quick & easy.

How do I link commandbuttons to combobox selection?

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
2 4446
1,044 Expert 1GB
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
269 256MB
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
  7. Private Sub CommandButton2_Click()
  8. With ComboBox1
  9. Cells(.ListIndex + 2, 3).Value = "P"
  10. End With
  11. End Sub
Dec 24 '19 #3

Post your reply

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

Similar topics

By using this site, you agree to our Privacy Policy and Terms of Use.