No, you can't use 'Option Buttons' on cells without the Userform to the best of my knowledge.
However, You can SIMULATE 'Option Buttons' by using Shapes, and assign macros to the shapes.
See the attached workbook written and tested using Excel 2003, which I expanded to 3 Simulated Option Buttons, and uses code very
similar to what existed with the Userform.
In the 'ThisWorkbook' module an optional initialization can be used:
Private Sub Workbook_Open()
Call SimulatedOptionButtonInitialization
End Sub
I arbitrarily divided the rest of the code into two modules:
ModSimulatedOptionButtons - which simulates the Option Buttons and interfaces with the Worksheet.
ModConvert - which contains code similar the original.
Code for ModSimulatedOptionButtons follows:
Option Explicit
Private SimulatedOptionButton1 As Boolean
Private SimulatedOptionButton2 As Boolean
Private SimulatedOptionButton3 As Boolean
Private Const SimulatedOptionButton1_CELL = "E9"
Private Const SimulatedOptionButton2_CELL = "E10"
Private Const SimulatedOptionButton3_CELL = "E11"
'''''''''''''''''''''''''''''''''''''''''''''''
'Get Routines - available for use by outside routines
'''''''''''''''''''''''''''''''''''''''''''''''
Function GetSimulatedOptionButton1Value() As Boolean
GetSimulatedOptionButton1Value = SimulatedOptionButton1
End Function
Function GetSimulatedOptionButton2Value() As Boolean
GetSimulatedOptionButton2Value = SimulatedOptionButton2
End Function
Function GetSimulatedOptionButton3Value() As Boolean
GetSimulatedOptionButton3Value = SimulatedOptionButton3
End Function
'''''''''''''''''''''''''''''''''''''''''''''''
'Set Routines
'''''''''''''''''''''''''''''''''''''''''''''''
Private Sub SetAllSimulatedOptionButtonsFalse()
SimulatedOptionButton1 = False
SimulatedOptionButton2 = False
SimulatedOptionButton3 = False
Range(SimulatedOptionButton1_CELL) = False
Range(SimulatedOptionButton2_CELL) = False
Range(SimulatedOptionButton3_CELL) = False
End Sub
Sub SetSimulatedOptionButton1()
If SimulatedOptionButton1 = True Then
'do nothing - if true - already selected
Else
Call SetAllSimulatedOptionButtonsFalse
SimulatedOptionButton1 = True
Range(SimulatedOptionButton1_CELL) = True
End If
End Sub
Sub SetSimulatedOptionButton2()
If SimulatedOptionButton2 = True Then
'do nothing - if true - already selected
Else
Call SetAllSimulatedOptionButtonsFalse
SimulatedOptionButton2 = True
Range(SimulatedOptionButton2_CELL) = True
End If
End Sub
Sub SetSimulatedOptionButton3()
If SimulatedOptionButton3 = True Then
'do nothing - if true - already selected
Else
Call SetAllSimulatedOptionButtonsFalse
SimulatedOptionButton3 = True
Range(SimulatedOptionButton3_CELL) = True
End If
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''
'Other Routines
'''''''''''''''''''''''''''''''''''''''''''''''
Sub SimulatedOptionButtonInitialization()
'Excel VBA initializes all Booleans to 'False'
'If you want to initialize a value to 'True' this
'routine should contain the 'True' value for the one
'Simulated Option button in the GROUP you want true.
'This Function is called from the Workbook_Open()
'code area in 'ThisWorkbook'.
Range(SimulatedOptionButton1_CELL) = False
Range(SimulatedOptionButton2_CELL) = False
Range(SimulatedOptionButton3_CELL) = False
Call SetSimulatedOptionButton2
End Sub
Code for ModConvert follows:
Sub ProcessConvert()
'NOTE: The '= True' is NOT NEEDED, but I like to use it for readability.
'With 3 choices - 'Select Case' is probably better than an 'If'
If GetSimulatedOptionButton1Value() = True Then
Call RadioButton1ConvertRoutine
ElseIf GetSimulatedOptionButton2Value() = True Then
Call RadioButton2ConvertRoutine
ElseIf GetSimulatedOptionButton3Value() = True Then
Call RadioButton3ConvertRoutine
End If
End Sub
Sub RadioButton1ConvertRoutine()
MsgBox "RadioButton1ConvertRoutine() stub"
End Sub
Sub RadioButton2ConvertRoutine()
MsgBox "RadioButton2ConvertRoutine() stub"
End Sub
Sub RadioButton3ConvertRoutine()
MsgBox "RadioButton3ConvertRoutine() stub"
End Sub
Bookmarks