Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
TRUE/FALSE MACRO using Option Buttons
I have and IF statement with multiple TRUE/FALSE parameters. I am trying to
convert it onto a userform using option buttons. for example on my excel sheet i have A1-A5 all false/true (with only 1 being true). How do I convert this over to my userform using multiple option option buttons; each option button linked to a cell A1-A5? If this is not clear please let me know. basically if A1 is true, A2-A5 are false if A2 is true A1 and A3-A5 are false, I need a macro on how to use this on a userform |
#2
Posted to microsoft.public.excel.misc
|
|||
|
|||
TRUE/FALSE MACRO using Option Buttons
Place a frame object on your user form, and then insert 5 option buttons
within the frame. In the form's code module you can use the following code as long as the option button have their default names and the worksheet you want to update is sheet 1, if not modify the code as needed: 'The following private function has one 'argument, the buttons number Private Sub OnOff(intButton As Integer) Dim ws As Worksheet Dim rng As Range Dim i As Integer Dim blnOnOff(4) As Boolean Set ws = ThisWorkbook.Sheets(1) Set rng = ws.Range("A1") Select Case intButton Case 1 blnOnOff(0) = True blnOnOff(1) = False blnOnOff(2) = False blnOnOff(3) = False blnOnOff(4) = False Case 2 blnOnOff(0) = False blnOnOff(1) = True blnOnOff(2) = False blnOnOff(3) = False blnOnOff(4) = False Case 3 blnOnOff(0) = False blnOnOff(1) = False blnOnOff(2) = True blnOnOff(3) = False blnOnOff(4) = False Case 4 blnOnOff(0) = False blnOnOff(1) = False blnOnOff(2) = False blnOnOff(3) = True blnOnOff(4) = False Case 5 blnOnOff(0) = False blnOnOff(1) = False blnOnOff(2) = False blnOnOff(3) = False blnOnOff(4) = True End Select For i = 0 To 4 rng.Offset(i).Value = blnOnOff(i) Next i Set ws = Nothing Set rng = Nothing End Sub 'To each option button assign the sub using the 'option button's number as the argument Private Sub OptionButton1_Change() OnOff 1 End Sub Private Sub OptionButton2_Change() OnOff 2 End Sub Private Sub OptionButton3_Change() OnOff 3 End Sub Private Sub OptionButton4_Change() OnOff 4 End Sub Private Sub OptionButton5_Change() OnOff 5 End Sub -- Kevin Backmann "Jase" wrote: I have and IF statement with multiple TRUE/FALSE parameters. I am trying to convert it onto a userform using option buttons. for example on my excel sheet i have A1-A5 all false/true (with only 1 being true). How do I convert this over to my userform using multiple option option buttons; each option button linked to a cell A1-A5? If this is not clear please let me know. basically if A1 is true, A2-A5 are false if A2 is true A1 and A3-A5 are false, I need a macro on how to use this on a userform |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Check box - true/false - i'd like a third option n/a | Excel Discussion (Misc queries) | |||
Excel Yes / No, True / False etc. cell selection buttons? | Excel Worksheet Functions | |||
Search for 2 true arguments and return true or false | Excel Discussion (Misc queries) | |||
Function to return True/False if all are validated as True by ISNU | Excel Worksheet Functions | |||
Reverse false and combine with true true value | Excel Worksheet Functions |