Hide Column When Checkbox (Forms Control) is checked

hrayani

Well-known Member
Joined
Jul 23, 2010
Messages
1,500
Office Version
  1. 2016
Platform
  1. Windows
Hello All,

The checkbox (Forms Control) is linked with cell D2 which returns True when the checkbox is checked and False when its unchecked


1582797594181.png


Then I am using the below code to hide/unhide rows

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    
If Range("D2").Value = True Then Rows("1:1").EntireRow.Hidden = True
If Range("D2").Value = False Then Rows("1:1").EntireRow.Hidden = False


End Sub

The problem is every time I need to edit any cell in the worksheet for the event to trigger.
Is there any possibility to hide or unhide rows as soon as the checkbox is checked or unchecked.

I also tried the selection change event but for that too I need to click on a cell for the event to trigger.

Any help would be appreciated.

Regards,

Humayun
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Glad to hear that & thanks for the feedback
 
Upvote 0
Just one more thing...

If i want to hide rows 1:3 & 5:6.... ??

I tired this but not working

Rows("1:3,5:6").Hidden = Shp.ControlFormat.Value = 1

EDIT:


Got it working like this :)

Range("1:3,5:6").EntireRow.Hidden = Shp.ControlFormat.Value = 1
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,873
Members
449,056
Latest member
ruhulaminappu

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