Run-time error '1004' when Clearing Data Help

lpo13

New Member
Joined
May 11, 2022
Messages
2
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi all, I've added VBA code to my project:
Private Sub CheckBox22_Click()
If CheckBox22 = True Then
[17:18].EntireRow.Hidden = False
Else: [17:18].EntireRow.Hidden = True
End If
End Sub

The problem is that this seems to be conflicting with my Clear Data macro- specifically if I select "Clear All Data" all checkboxes should be returned to TRUE/FALSE depending on the values within a group of cells. This particular checkbox is set to be False by default on selecting Clearing Data.

If I click Clear Data when this checkbox is False, then there's no issue and the rest of the checkboxes get reset (plus any information added in textboxes and radio buttons).

If I click Clear Data when this checkbox is True, then I get the following error message:

Run-time error '1004':
Unable to set the Hidden property of the Range class
with the following line highlighted:
Else: [17:18].EntireRow.Hidden = True

Is there any way around this? If I remove the highlighted line, then if I unselect Checkbox22, the rows are visible, but if I select Checkbox22, then the rows are still visible, so that isn't an option.

Many thanks
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Sorry I noticed that I didn't include the Clear Data code that is causing the issue:

Sub ClearData()
Dim rngSource As Range, rngTarget As Range
Dim Sheet As Worksheet


If Sheet.[B9] = True Then
Set rngSource = Sheet.Range("BE11").CurrentRegion
Set rngTarget = Sheet.Range("AE11")
rngSource.Copy rngTarget
Set rngSource = Nothing: Set rngTarget = Nothing

Sheet.Range("Y11:Y57") = ""
Sheet.Range("DE11:DK57") = ""
Sheet.Range("FE11:FK57") = ""
Sheet.Range("GE11:GN57") = False

End If

Next

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,924
Members
452,366
Latest member
TePunaBloke

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