Help with a option buttons located in a userform

  • Thread starter Thread starter mav93
  • Start date Start date
M

mav93

Hi everyone

I have two option buttons in user form1
I'm wondering what code I would need to use and where it would go
to link the that I have placed in to userform 1 to cell "A1" in
worksheet 'Material takeoff'

this is my first time with userforms and the properties and I'm just a
newbie at VBA

If option buttion 1 in the user form is selected then cell "A1" should
= 1
If option buttion 2 in the user form is selected then cell "A1" should
= 2
if neither are selected it should = 0 or blank
also the value in cell A1 to change before the userform is closed

Thanks in advance for any help
 
Put this code in your userform (right click on Userform==>view code and
copy/paste)

A1 (on Sheet2 in the example .. change to suit your needs ...) is set 0
when the form is loaded.

Optionbutton is TRUE when selected which is numerically -1: hence muliples
of -1 and -2 to get 1 & 2 in A1

HTH

Private Sub OptionButton1_Click()
Worksheets("Sheet2").Range("A1") = OptionButton1.Value * -1
End Sub
Private Sub OptionButton2_Click()
Worksheets("Sheet2").Range("A1") = OptionButton2.Value * -2
End Sub
Private Sub UserForm_Initialize()
Worksheets("Sheet2").Range("A1") = 0 '<=== set A1 to zero
End Sub
 
Back
Top