VBA Code Needed that will Hide / Unhide a row when used with a "Check Box"

Barryoffshore

Board Regular
Joined
Feb 21, 2005
Messages
73
I need a VBA code that will when used with a Form Control "Check Box" will unhide / hide a row. To be more exact, I'm needind the code to "Hide" row 34 when unchecked and "Unhide" the same row when checked. Can someone help me please. By the way, I'm using Excel 2010. Thank you!!!
 
Last edited:

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Hi,t
Try this.

Code:
Sub CheckBox1_Click()
Sheets(1).Rows(34).Hidden = Not Sheets(1).CheckBoxes("Check Box 1").Value = 1
End Sub

Code in standard module & assigned to your checkbox. Change names as required.

Dave
 
Upvote 0
Well, that didn't work... It returned an error (not a bug) - error #400 - whatever that means???

I take it that's a Thank-you for responding to my request for assistance?

Is your worksheet protected & did you rename the checkbox / worksheet as stated if required?

Dave
 
Upvote 0
Actually I do thank you very much - I need all the help I can get!!! No, there are no protections on the workbook. More than likely I'm just doing something wrong... I'm still learning this stuff and I tend to make a lot of mistakes.
 
Upvote 0
Your request was for assistance with a "Form Control Check Box" which would reside on a worksheet. Are you actually referring to an ActiveX checkbox on a UserForm or worksheet? If so, code would look this:

Code:
Private Sub CheckBox1_Click()
Sheets(1).Rows(34).Hidden = Not Me.CheckBox1.Value
End Sub

and would be placed either in your forms or worksheets code page.
Dave
 
Last edited:
Upvote 0
Thank you again for responding so quickly!!! This time it came back with "Compile Error - Improper use of Me keyword". I truly have no idea what that means either :(
 
Upvote 0
where is this checkbox on a userform? or a worksheet?

and have you placed the code either in the forms or worksheet code page and NOT in a standard module?
 
Last edited:
Upvote 0
It's on the worksheet - Sheet2

and where have you placed the code? & did you update it for correct sheet checkbox name?

If Checkbox is Activex then you need to Right Click Tab > View Code & place code there.

If its a Forms checkbox then place first example in a standard module & assign to your checkbox.

All names will need updating to match your Sheet / Checkbox names.

Dave
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,514
Messages
6,125,272
Members
449,219
Latest member
daynle

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