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

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
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,215,059
Messages
6,122,916
Members
449,093
Latest member
dbomb1414

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