Excel VBA Checkbox..... Pulling my hair out

cizzett

Board Regular
Joined
Jan 10, 2019
Messages
121
Ok So I have checkboxes I use in If statements thorughout my workbook and after adding one final it seems no matter what I do it will not recognize the value

I have declare the variable for the checkbox as normal

Code:
Dim RnFinalCB As CheckBox: Set RnFinalCB = Ws.Shapes("RnFinalCB").OLEFormat.Object

 If RunFinalCB.Value = False Then
Call Prep
End If

No matter what I do as long as this in in the code it skips the call and moves past wether the checkbox is true or false doesnt matter.

Any Ideas why? or how to resolve?

As I said I use this same thing on other checkboxes in my workbook and it works fine. So I am stumped.
 
Last edited:

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
No I intentionally left the U out because I renamed the checkbox hoping it just didnt like the naming or something, no idea why it wont recognize this.

In the same code at the end I set it to make the checkbox value True and it will do that no problem so I know it sees the checkbox just don't know why it wont recognize false at before the call.
 
Last edited:
Upvote 0
SO I tweaked it to a not statement and that seems to work, for some reason it would not recognize the false status of the checkbox.

Code:
[COLOR=#333333]Dim RnFinalCB As CheckBox: Set RnFinalCB = Ws.Shapes("RnFinalCB").OLEFormat.Object[/COLOR]
 If Not RunFinalCB.Value = True Then
Call Prep [COLOR=#333333]End If[/COLOR]
 
Upvote 0
If this is a checkbox from the forms toolbar, the states are xlOn (1) and xlOff (-4146), not True and False.
 
Upvote 0
I Don't understand your Code, You do not have the Worksheet ("Ws") or the Checkbox "RunFinalCb" declared or set.
I Imagine you do not have "Option Explicit", else you would hit an error.

The code below works for me !!!

Code:
[COLOR="Navy"]Sub[/COLOR] MG10May22
[COLOR="Navy"]Dim[/COLOR] RnFinalCB [COLOR="Navy"]As[/COLOR] CheckBox
[COLOR="Navy"]Dim[/COLOR] Ws [COLOR="Navy"]As[/COLOR] Worksheet
 [COLOR="Navy"]Set[/COLOR] Ws = ActiveSheet
 [COLOR="Navy"]Set[/COLOR] RnFinalCB = Ws.Shapes("RnFinalCB").OLEFormat.Object
    [COLOR="Navy"]If[/COLOR] RnFinalCB.Value = xlOn [COLOR="Navy"]Then[/COLOR]
        Call prep
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Or perhaps simpler Like:-
Code:
[COLOR="Navy"]Sub[/COLOR] CheckBox5_Click()
[COLOR="Navy"]If[/COLOR] ActiveSheet.Shapes(Application.Caller).OLEFormat.Object.Value = xlOn [COLOR="Navy"]Then[/COLOR] Call prep
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,151
Members
453,021
Latest member
Justyna P

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