Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / General Excel Questions / March 2008

Tip: Looking for answers? Try searching our database.

TRUE/FALSE MACRO using Option Buttons

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jase - 28 Mar 2008 21:21 GMT
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
Kevin B - 28 Mar 2008 22:15 GMT
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

Signature

Kevin Backmann

> 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
[quoted text clipped - 5 lines]
> if A2 is true A1 and A3-A5 are false, I need a macro on how to use this on a
> userform
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.