code for 'If' statement that checks to see if any checkboxes are checked inside a frame

kbishop94

Active Member
Joined
Dec 5, 2016
Messages
458
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I have 6 checkboxes inside a frame ('fraCARbase'). I need an If statement that if any of the 6 checkboxes are 'ticked;, 'Then'... (I know this is probably really simple, but I cant seem to get it right and I want to reduce my current code that looks at each individual checkbox.)

Thanks!
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Are your controls on a worksheet or on a UserForm?
Oh shoot, I apologize. I forgot to mention that lol

This is on a userform.

The checkboxes (sorry, there are 8, not 6 as I also incorrectly mentioned.) are in this frame and if any are checked, I am going to have the frame above it turn yellow to indicate the change:

frame2.jpg
 
Upvote 0
Maybe something like this code in whatever event procedure you are using for this...
VBA Code:
  Dim Cntrl As Object
  For Each Cntrl In fraCARbase.Controls
    If TypeOf Cntrl Is MSForms.CheckBox Then
      If Cntrl.Value = True Then
        ' The Checkbox is checked
        ' Do whatever you need to here
        fraCARbase.BackColor = vbYellow
        Exit For
      End If
    End If
  Next
 
Upvote 0
Solution
Maybe something like this code in whatever event procedure you are using for this...
VBA Code:
  Dim Cntrl As Object
  For Each Cntrl In fraCARbase.Controls
    If TypeOf Cntrl Is MSForms.CheckBox Then
      If Cntrl.Value = True Then
        ' The Checkbox is checked
        ' Do whatever you need to here
        fraCARbase.BackColor = vbYellow
        Exit For
      End If
    End If
  Next
That did it! Thank you, Rick Rothstein (y)
 
Upvote 0

Forum statistics

Threads
1,214,839
Messages
6,121,891
Members
449,058
Latest member
Guy Boot

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