Option button

ojhawkins

New Member
Joined
Nov 17, 2011
Messages
39
Hi all,

I have this simple code (in a Module) that currently references "A2" & "A3" for either "buy" or "sell". Instead I want it to use the OptionButton for either true or false to determine if it is a buy or sell.

I don't want the OptionButton to put a value in a cell to determine if it is true or false (hope this makes sense) example "if optionbutton1 = true then range x = 1 etc" then use this to determine if is a buy or sell.

I am really stuck on how to do this.

Cheers,
O


Sub test()

Dim x As Double
Dim y As Double

Dim strOrder1 As String
Dim strOrder2 As String

strOrder1 = Range("a2").Value
strOrder2 = Range("a3").Value

If strOrder1 = "buy" Then
x = Range("d2").Value * -1
Else
If strOrder1 = "sell" Then x = Range("c2").Value
End If

If strOrder2 = "buy" Then
y = Range("d3").Value * -1
Else
If strOrder2 = "sell" Then y = Range("c3").Value
End If

Range("e2") = x + y

End Sub


2wciogn.png
 
Last edited:

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Hi,
under the change event you could do something like
Code:
if optionbutton1.value = true then
sheets("Sheet1").range("A1").value = "1"
end if
 
Upvote 0
Hi,
under the change event you could do something like
Code:
if optionbutton1.value = true then
sheets("Sheet1").range("A1").value = "1"
end if

Is there any way it can be done with out putting a value in a cell? Can the OptionButton store a value to it can called in the program some how?
 
Upvote 0
I don't understand what you mean "store a value to it can called in the program". What you want to determine basing on Optionbuttons?
 
Upvote 0
I don't understand what you mean "store a value to it can called in the program". What you want to determine basing on Optionbuttons?

Example below. How can I use the OptionButton by

Sub test()

Dim x As Double
Dim y As Double

Dim strOrder1 As String
Dim strOrder2 As String

strOrder1 = Range("a2").Value
strOrder2 = Range("a3").Value

If Optionbutton1 = True Then
x = Range("d2").Value * -1
Else

If Optionbutton2 = True Then x = Range("c2").Value
End If


Instead of the below referencing a cell

If strOrder2 = "buy" Then
y = Range("d3").Value * -1
Else
If strOrder2 = "sell" Then y = Range("c3").Value
End If

Range("e2") = x + y

End Sub
 
Upvote 0

Forum statistics

Threads
1,226,693
Messages
6,192,471
Members
453,726
Latest member
JoeH57

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top