If statement in macro

Viking88

Board Regular
Joined
Apr 18, 2003
Messages
103
I am relatively new to macros so please bare with me. I have a check box in my spreadsheet, but I want to hide rows 5-12 if the box is unchecked and show those rows if the box is checked. How can I do this with a macro. Also I have the cell link set up as cell E3. I can write the basic macro to hide the rows, but I am not sure how to incorporate the "if" scenario.

Thanks.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
If you're using a checkbox from the Controls Toolbox (not the Forms toolbar), you could assign this to the checkbox's click event:
Code:
Private Sub CheckBox1_Click()
    If CheckBox1.Value = False Then
        Sheets("Sheet1").Rows("5:12").Hidden = True
    Else
        Sheets("Sheet1").Rows("5:12").Hidden = False
    End If
End Sub
 
Upvote 0
Hi,

if the check box is from control toolbox, try this (the code must into the class module of the table):

Code:
Private Sub CheckBox1_Click()
    Rows("5:12").Hidden = Not CheckBox1.Value
End Sub
If the check box is from form toolbar, try this (the code belonged in a general module and you must assign the macro of the check box):

Code:
Public Sub Hidden_Click()
    Rows("5:12").Hidden = Not ActiveSheet.Shapes(Application.Caller).OLEFormat.Object.Value = 1
End Sub
Case_Germany
 
Upvote 0

Forum statistics

Threads
1,214,599
Messages
6,120,449
Members
448,966
Latest member
DannyC96

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