Checkbox runs macro when clicked, but not when button "clicks" it.

excelisfunusually

New Member
Joined
Jul 29, 2015
Messages
22
I asked this question in a similar forum, but wanted to solicit others for their ideas as well. I have groups of checkboxes (not actually grouped programmatically) that should be checked when a button is clicked. Once checked an additional code should run.

I received one reply that maybe adding the code for the checkboxes to the button's code would solve the issue. It does if I run the code from the VBA editor, but when the button is clicked on the spreadsheet I only have checked boxes. No additional action. I have provided the modified code below:

Code:
Public s As IntegerSub Button1_Click()
If s = 0 Then
        ActiveSheet.CheckBoxes("Check Box 2").Value = 1
            If Range("I1").Value >= Range("H5").Value Then
            Range("I5").Formula = "=$E5"
            End If
    
            If Range("J1").Value >= Range("H5").Value Then
            Range("J5").Formula = "=$E5"
            End If
    
            If Range("K1").Value >= Range("H5").Value Then
            Range("K5").Formula = "=$E5"
            End If
    
            If Range("L1").Value >= Range("H5").Value Then
            Range("L5").Formula = "=$E5"
            End If
    
            If Range("M1").Value >= Range("H5").Value Then
            Range("M5").Formula = "=$E5"
            End If
    
            If Range("N1").Value >= Range("H5").Value Then
            Range("N5").Formula = "=$E5"
            End If
    
            If Range("O1").Value >= Range("H5").Value Then
            Range("O5").Formula = "=$E5"
            End If
    
            If Range("P1").Value >= Range("H5").Value Then
            Range("P5").Formula = "=$E5"
            End If
    
            If Range("Q1").Value >= Range("H5").Value Then
            Range("Q5").Formula = "=$E5"
            End If
    
            If Range("R1").Value >= Range("H5").Value Then
            Range("R5").Formula = "=$E5"
            End If
    
            If Range("S1").Value >= Range("H5").Value Then
            Range("S5").Formula = "=$E5"
            End If
    
            If Range("T1").Value >= Range("H5").Value Then
            Range("T5").Formula = "=$E5"
            End If


        ActiveSheet.CheckBoxes("Check Box 3").Value = 1
        ActiveSheet.CheckBoxes("Check Box 4").Value = 1
        ActiveSheet.CheckBoxes("Check Box 5").Value = 1
        ActiveSheet.CheckBoxes("Check Box 6").Value = 1
        ActiveSheet.CheckBoxes("Check Box 7").Value = 1
        ActiveSheet.CheckBoxes("Check Box 8").Value = 1
        ActiveSheet.CheckBoxes("Check Box 9").Value = 1
        ActiveSheet.Shapes.Range(Array("Button 1")).Select
        Selection.Characters.Text = "Uncheck All"
        s = 1
    ElseIf s = 1 Then
        ActiveSheet.CheckBoxes("Check Box 2").Value = -4146
            Range("I5:T5").Value = ""
        ActiveSheet.CheckBoxes("Check Box 3").Value = -4146
        ActiveSheet.CheckBoxes("Check Box 4").Value = -4146
        ActiveSheet.CheckBoxes("Check Box 5").Value = -4146
        ActiveSheet.CheckBoxes("Check Box 6").Value = -4146
        ActiveSheet.CheckBoxes("Check Box 7").Value = -4146
        ActiveSheet.CheckBoxes("Check Box 8").Value = -4146
        ActiveSheet.CheckBoxes("Check Box 9").Value = -4146
        ActiveSheet.Shapes.Range(Array("Button 1")).Select
        Selection.Characters.Text = "Check All"
        s = 0
    End If
    End Sub

Do you see anything that I am doing wrong?

Thanks!

Also posted here https://www.excelforum.com/excel-pr...en-clicked-but-not-when-button-clicks-it.html
 
Last edited by a moderator:

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
This was solved. I had to move the modified code to the same module containing the checkbox code. I also ended up calling the checkbox code instead. Rather than using all the if statements, I had already written that code under Checkbox2_Click, so I called it after the button changes the value of the checkbox to 1. The code is a lot cleaner, I just showed it this way to see if I had done anything wrong.
 
Upvote 0

Forum statistics

Threads
1,214,525
Messages
6,120,051
Members
448,940
Latest member
mdusw

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