Code for OptionBox

N

Noepie

Hello,

I have a sheet where people can choose between two options. I make use of
the OptionButton in the VBA Editor. What I want is that when Option 1 is
chosen, the worksheet fills in the value from A1 in to B1. When Option 2 is
chosen, the value from A2 should be filled in in to B1. How can I achieve
this?

Kind regards,

Noepie
 
C

Chip Pearson

Assuming you are using the option buttons from the Controls command
bar not the Forms command bar, you can use code like the following:


Private Sub OptionButton1_Click()
Range("A1").Value = Range("B1").Value
End Sub

Private Sub OptionButton2_Click()
Range("A2").Value = Range("B1").Value
End Sub

Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
N

Noepie

Thanx Chip!

Chip Pearson said:
Assuming you are using the option buttons from the Controls command
bar not the Forms command bar, you can use code like the following:


Private Sub OptionButton1_Click()
Range("A1").Value = Range("B1").Value
End Sub

Private Sub OptionButton2_Click()
Range("A2").Value = Range("B1").Value
End Sub

Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top