Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 117
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,316
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check box - true/false - i'd like a third option n/a Kelly 1st Excel Discussion (Misc queries) 6 February 24th 10 01:23 PM
Excel Yes / No, True / False etc. cell selection buttons? Harrison[_2_] Excel Worksheet Functions 1 July 4th 07 04:50 AM
Search for 2 true arguments and return true or false David Excel Discussion (Misc queries) 3 July 15th 06 10:18 AM
Function to return True/False if all are validated as True by ISNU Tetsuya Oguma Excel Worksheet Functions 2 March 15th 06 10:28 AM
Reverse false and combine with true true value Emmie99 Excel Worksheet Functions 5 August 17th 05 04:38 PM


All times are GMT +1. The time now is 08:03 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"