VBA Based with Checkboxes

bnichols

New Member
Joined
Dec 28, 2022
Messages
14
Office Version
  1. 365
Platform
  1. MacOS
Hello, looking for some help with some specific coding. I think I listed everything in the mini sheet below, but I'm trying to get a few different codes to run off a box being checked and dependent on multiple cell totals, some by manual entry and some by formula calculation. At the end, I wanted to have a macro button but have it only run once all boxes are checked. I tried a few different ways with codes I found in other threads but haven't had much luck getting it to work. Thanks for any help provided

Fyi im running Excel on a MAC


Test Workbook.xlsx
ABCDEFGHIJKLM
5
6Sales123456Check BoxSales Entered?C:H6If each cell (not total) is number (nothing), if blank or not number "message" and doesn’t allow box to be checked
7Labor123456Check BoxLabor Entered?C:H7Same as above
8Online Purchases100Number result of formulaCheck BoxTotals?C:H9Same as above
9Ctuit Totals123456Check BoxOnline Purchases?C8Pop up yes/no message box each checkbox
10Variance-200Number result of formulaCheck BoxVariance Less Than $100?C10If cell total is between -$100 and $100 (nothing), if less than -100 or greater than 100 "message" and doesn’t allow box to be checked
11
12Macro ButtonMacro runs action that hides rows 6 - 16 and unhides rows 17 - 27, however it will only run when all check boxes are checked
13If button is pressed, If all boxes not checked run macro, if not all boxes checked "message"
14
2
Cell Formulas
RangeFormula
C8C8=50+50
C10C10=-100-100
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Hey, try code below:

VBA Code:
Sub CheckAllBeforeRun()

Dim sh As Worksheet
Set sh = ActiveSheet

Dim check As Boolean

    If sh.Shapes.Count > 0 Then
    
        'Iterate through all the shapes on the sheet
        For Each shp In sh.Shapes
        
            'If shape type is Form Control
            If shp.Type = msoFormControl Then
            
                'If Form Control is Check Box
                If shp.FormControlType = 1 Then
                
                    If shp.ControlFormat.Value <> 1 Then
                    
                    MsgBox ("Not marked.")
                    Exit Sub
                    
                    End If
                 
                End If
                
            End If
                
        Next shp
        
        MsgBox ("All marked.")
        'Call sub
        
    End If

End Sub

It looks for the Form Controls check box as shown below:

1672401241744.png
1672401266166.png
 
Upvote 0
Hey, try code below:

VBA Code:
Sub CheckAllBeforeRun()

Dim sh As Worksheet
Set sh = ActiveSheet

Dim check As Boolean

    If sh.Shapes.Count > 0 Then
   
        'Iterate through all the shapes on the sheet
        For Each shp In sh.Shapes
       
            'If shape type is Form Control
            If shp.Type = msoFormControl Then
           
                'If Form Control is Check Box
                If shp.FormControlType = 1 Then
               
                    If shp.ControlFormat.Value <> 1 Then
                   
                    MsgBox ("Not marked.")
                    Exit Sub
                   
                    End If
                
                End If
               
            End If
               
        Next shp
       
        MsgBox ("All marked.")
        'Call sub
       
    End If

End Sub

It looks for the Form Controls check box as shown below:

View attachment 81770 View attachment 81771
Thank you, I was able to get that working! Is there a way to get it to use selective checkboxes? The intent was to have 3 sets of the same check boxes on the same sheet and each macro would hide/unhide just a particular set of rows
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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