Checkbox Not Showing (nor acting) As "Checked" until Macro Procedure Ends

watari_pg

New Member
Joined
Mar 7, 2022
Messages
5
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I'm running into a problem with a Macro which contains several checkboxes and subroutines.

Sub 1 is supposed to do something when Checkbox 1 is checked.
Sub 2 is supposed to do something else when Checkbox 2 is checked.
Sub 3 is supposed to erase everything done before (by either Sub 1 or Sub 2) when either Checkbox 1 or Checkbox 2 is unchecked.

The problem I am having is that when I check, say, Checkbox 1, it doesn't show the box as having been checked until Sub 1 and another unexpected subroutine (Sub 3) are completed. Also, until getting to this point, the checkbox also behaves as though it were unchecked and calls Sub 3 as well, although it should only be calling Sub 1 and coming to an end at that point.

Sub Insanity()

If ActiveSheet.CheckBoxes("Check Box 4").Value = xlOn Then
Proc1
End If

If ActiveSheet.CheckBoxes("Check Box 4").Value = xlOff Then
EraseIt
End If

If ActiveSheet.CheckBoxes("Check Box 6").Value = xlOn Then
Proc2
End If

If ActiveSheet.CheckBoxes("Check Box 6").Value = xlOff Then
EraseIt
End If

End Sub
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
The code you've posted does nothing other than call procedures based on the current state of the check boxes.
You need to show us the procedures being called.
 
Upvote 0
The code you've posted does nothing other than call procedures based on the current state of the check boxes.
You need to show us the procedures being called.
Thank you very much for your reply. I wondered whether I should have posted everything, but the Macro is kind of verbose, so I was reluctant to do that.

The good news is I figured out what the problem was and have fixed it.

It wasn't that the checkboxes weren't working properly, or that the sub-procedures were causing a problem. The problem was that the main procedure Insanity() was always checking for the status of all of the checkboxes every time it went through it, so for example, if I checked Box 1 (and ran through Proc1) with Box 2 unchecked, it would go through the erase procedure twice when Box 1 was unchecked because in that case both Box 1 and Box 2 were unchecked. Also, if both Box 1 and Box 2 were checked with Proc1 and Proc 2 having been performed, then if you unchecked only one of the Boxes (say Box 1), it ran through the erase procedure based on Box 1 being unchecked, but also would rerun Proc 2 again (since that box was still checked).

Anyway, after a lot of attempts, I figured out how to avoid the problem, so I guess I solved it on my own.

I very much appreciate your advice, and will be more complete with my next questions, should they come up.
 
Upvote 0
I figured out how to avoid the problem, so I guess I solved it on my own.

Good to hear you got the solution.

If you would like to post the solution then it is perfectly fine to mark your post as the solution to help future readers. Otherwise, please do not mark a post that doesn't contain a solution.
 
Upvote 0
Good to hear you got the solution.

If you would like to post the solution then it is perfectly fine to mark your post as the solution to help future readers. Otherwise, please do not mark a post that doesn't contain a solution.

Thanks, I'm completely new here and learning the ropes. Of course I've used Excel for simpler projects in the past, but this one is fret with difficulties (long with tons of subroutines with easily confusable variables). It's kind of a dopey project and mainly a learning exercise for me. I don't think anyone would profit from the solution.

Anyway, I'll obey your guidance in the future.

Thanks a lot.

Paul
 
Upvote 0

Forum statistics

Threads
1,215,444
Messages
6,124,893
Members
449,194
Latest member
JayEggleton

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