Get value from command button VBA

2k Views Asked by At

I have created A userform with few command buttons.

I can't seem to figure out how do I get the information from them.

I want to open this userform from another one and then I want the user to choose an option from one of the buttons which will change a specific cell in the table itself

the userform I created

I did not write anything on this userform therefor there is no code from it to show only the design.

how do get the information from the buttons to be written in A specific cell on a specific worksheet?

1

There are 1 best solutions below

0
On BEST ANSWER

double click on one of the buttons, in the code menu a new sub should appear. this looks something like:

Sub CommandButton1_onClick()
End sub

Alongside this event method, it also has a few properties. The one that is usefull here is the CommandButton1.Value, this represents the state of the button (either true or false iirc).

So build for each button (I strongly advice giving them custom names to prevent getting lost in the trouble) as sub like this:

Sub CommandButton1_onClick()
   if CommandButton1.Value then
      ThisWorkBook.WorkSheets("WorksheetName").Range("YourRange").Value = "Some value"
   else
      ThisWorkBook.WorkSheets("WorksheetName").Range("YourRange").Value = ""
   end if
End sub