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

kbishop94

Active Member
Joined
Dec 5, 2016
Messages
423
Office Version
  1. 2010
Platform
  1. Windows
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

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
38,058
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Are your controls on a worksheet or on a UserForm?
 

kbishop94

Active Member
Joined
Dec 5, 2016
Messages
423
Office Version
  1. 2010
Platform
  1. Windows
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
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
38,058
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
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
 
Solution

kbishop94

Active Member
Joined
Dec 5, 2016
Messages
423
Office Version
  1. 2010
Platform
  1. Windows
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)
 

Forum statistics

Threads
1,181,633
Messages
5,931,109
Members
436,776
Latest member
kranda

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
Top