Multiple Checkbox options

JaredW

New Member
Joined
Mar 24, 2012
Messages
7
Hi

i have a userform with 9 frames and 9 checkboxes, i want each checkbox to control the visibility of a frame and that of the other frames..
for example:
if checkbox1=true then i want it to just show frame 1
and if checkbox1 & checkbox2=true then i want it to show frame1 and frame2 below frame1 and so on,

i need to give the userform the ability to show any number of the frames depending on the combination of checkboxes that have been selected.

i tried the code below, but it doesn't seem to work past the 2nd IF

Private Sub checkbox5_Click()
If CheckBox5 = True Then
If CheckBox4 = True Then
Frame4.Visible = True
Frame4.Left = 6
Frame4.Top = 294
Frame5.Visible = True
Frame5.Left = 6
Frame5.Top = 506
Else
If CheckBox5 = True Then
If CheckBox4 = False Then
Frame4.Visible = False
Frame5.Visible = True
Frame5.Left = 6
Frame5.Top = 198
Else
If CheckBox5 = False Then
Frame2.Visible = False
End If
End If
End If
End If
End If

End Sub

is there a way to get this to work?:confused:
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Why not just check the value of each checkbox to determine which frames to make visible?

Also to position the frames using a variable for Top.

Something like this perhaps, which can be called from the click events of the checkboxes.
Code:
Sub HideShowFrames()
Dim I As Long
Dim lngTop As Long
    
    lngTop = 48
    For I = 1 To 10
        If Me.Controls("Checkbox" & I).Value = True Then
            With Me.Controls("Frame" & I)
                .Visible = True
                .Top = lngTop
                lngTop = lngTop + 38
            End With
            
        Else
            Me.Controls("Frame" & I).Visible = False
        End If
    Next I
End Sub
Note, I've used different values for the top(48) and the distance(38) between the visible frames so I could fit all 10 frames on my form.
 
Upvote 0
Hello JaredW,

If you use the Change event for each CheckBox then your code can be greatly shortened. Here is an example using CheckBox1 and Frame1.
Code:
Private Sub CheckBox1_Change()
    Frame1.Visible = CheckBox1.Value
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,581
Messages
6,125,658
Members
449,247
Latest member
wingedshoes

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