By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,264 Members | 1,237 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,264 IT Pros & Developers. It's quick & easy.

Excel Checkbox

100+
P: 142
In excel have one checkbox and one commondbutton. Inside the checkbox VBA, when if checkbox=true, then do a run and write a text to excel cell, when if checkbox=false, then remove the text in excel cell. And in that commondbutton, it have VBA checkbox=false, and it remove will the checkmark and the text, but all i want is just remove the checkmark but not the text in excel cell. Any idea?

Checkbox
Expand|Select|Wrap|Line Numbers
  1. If checkbox=True then
  2. ...
  3. cell(1,1)=123
  4. end If
  5. If checkbox=False then
  6. cell(1,1)=Empty
  7. End If
  8.  
commondbutton
Expand|Select|Wrap|Line Numbers
  1. ...
  2. checkbox=False
  3.  
Apr 13 '07 #1
Share this Question
Share on Google+
4 Replies


Expert 5K+
P: 8,434
I'd say the problem is that when your commandbutton turns off the checkbox, it triggers the same event as when you click on the checkbox. So your code sets the cell to Empty.

I can think of a couple of ways around this...
  • In the commandbutton code, do this...
    • Save the value from the cell
    • Clear the checkbox
    • Put the value back in the cell.
  • Create a flag (probably a Boolean variable at module level). In the checkbox code, don't do anything if the flag is set. In the commandbutton code, do this:
    • Set the flag
    • Clear the checkbox
    • Clear the flag
Apr 14 '07 #2

100+
P: 142
I'd say the problem is that when your commandbutton turns off the checkbox, it triggers the same event as when you click on the checkbox. So your code sets the cell to Empty.

I can think of a couple of ways around this...
  • In the commandbutton code, do this...
    • Save the value from the cell
    • Clear the checkbox
    • Put the value back in the cell.
  • Create a flag (probably a Boolean variable at module level). In the checkbox code, don't do anything if the flag is set. In the commandbutton code, do this:
    • Set the flag
    • Clear the checkbox
    • Clear the flag
How to set the flag?
Apr 16 '07 #3

100+
P: 142
How to set the flag?
got it. thanks
Apr 16 '07 #4

Expert 5K+
P: 8,434
How to set the flag?
"Flag" in this context is just a general term for a value that you set to indicate a specific condition. In this case, if you do go this way I'd suggest you create a variable at the module or form level, of type Boolean, and use that as your flag. The flag isn't any particular feature of Visual Basic or anything, just a variable that you use to record the fact that you are doing something.

In this case, the fact that the flag is "set" (True, if the type is boolean) indicates "I am changing the checkbox, it's not the user, so don't take any notice of it". The idea is to have your code in the checkbox's change event not do anything if it was your own code elsewhere that made the change - only when the user changes it.

This is quite a common technique in programming, especially event-driven stuff like in VB.
Apr 16 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.