Reno9199

New Member
Joined
Mar 13, 2015
Messages
4
Hi. I am not a VB programmer, but I expect the answer would be easy for those who are. I have a simple VB routine running on a spreadsheet that clears the contents of a cell when the value has been changes. I would like to add a checkbox to my spreadsheet to turn on or off this feature (basically bypass the code). Have not been having much luck. Tried simple GoTo but evidently did not do it right as I cannot get it to react to the checkbox. Any suggestion are greatly appreciated. A sample of code is below:

Private Sub Worksheet_Change(ByVal Target As Range)
'Comment: if severity changes, clear Solution and Risk Reduction Method

If Target.Address = "$E$19" Then Range("$T$19").ClearContents
If Target.Address = "$E$20" Then Range("$T$20").ClearContents
If Target.Address = "$E$21" Then Range("$T$21").ClearContents
If Target.Address = "$E$22" Then Range("$T$22").ClearContents
If Target.Address = "$E$23" Then Range("$T$23").ClearContents
If Target.Address = "$E$24" Then Range("$T$24").ClearContents
If Target.Address = "$E$25" Then Range("$T$25").ClearContents
If Target.Address = "$E$26" Then Range("$T$26").ClearContents
If Target.Address = "$E$27" Then Range("$T$27").ClearContents
If Target.Address = "$E$28" Then Range("$T$28").ClearContents
If Target.Address = "$E$29" Then Range("$T$29").ClearContents

on and on until
If Target.Address = "$G$124" Then Range("$T$124").ClearContents
If Target.Address = "$G$125" Then Range("$T$125").ClearContents
If Target.Address = "$G$126" Then Range("$T$126").ClearContents
If Target.Address = "$G$127" Then Range("$T$127").ClearContents
If Target.Address = "$G$128" Then Range("$T$128").ClearContents
If Target.Address = "$G$129" Then Range("$T$129").ClearContents


End Sub


Obviously not elegant, but works fine for what I need.
Thanks in advance
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Comment: if severity changes, clear Solution and Risk Reduction Method


If CheckBox1.Value = True Then
    Exit Sub
End If


If Target.Address = "$E$19" Then Range("$T$19").ClearContents
If Target.Address = "$E$20" Then Range("$T$20").ClearContents
If Target.Address = "$E$21" Then Range("$T$21").ClearContents
If Target.Address = "$E$22" Then Range("$T$22").ClearContents
If Target.Address = "$E$23" Then Range("$T$23").ClearContents
If Target.Address = "$E$24" Then Range("$T$24").ClearContents
If Target.Address = "$E$25" Then Range("$T$25").ClearContents
If Target.Address = "$E$26" Then Range("$T$26").ClearContents
If Target.Address = "$E$27" Then Range("$T$27").ClearContents
If Target.Address = "$E$28" Then Range("$T$28").ClearContents
If Target.Address = "$E$29" Then Range("$T$29").ClearContents


'on and on until
If Target.Address = "$G$124" Then Range("$T$124").ClearContents
If Target.Address = "$G$125" Then Range("$T$125").ClearContents
If Target.Address = "$G$126" Then Range("$T$126").ClearContents
If Target.Address = "$G$127" Then Range("$T$127").ClearContents
If Target.Address = "$G$128" Then Range("$T$128").ClearContents
If Target.Address = "$G$129" Then Range("$T$129").ClearContents




End Sub
 
Upvote 0
Thank you for the quick response. I entered your suggestion, however now I get a Run-Time error '424'" Object required. When I go to the debugger, the If CheckBox line is highlighted. I figured the "name" of the checkbox maybe was incorrect, but the only place I saw where I could enter anything was in the Format Control box when I right-clicked on the checkbox. Only place I saw to do any edit of naming was the Alt Text tab. This tab had a Check Box 433 value. I did try taht name in the VB code, but still had the same error message! Appreciating your patience and help. What am I missing now???

Does it matter if my checkbox is an ActiveX control or a Form Control?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,052
Messages
6,122,878
Members
449,097
Latest member
dbomb1414

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