Hiding rows based on a cell's value

mikeb7500

Board Regular
Joined
Jul 30, 2014
Messages
99
What's the best way to hide certain rows based on a cell's value of "0"? Can it be done with an IF Statement, or must it be done with VBA?
Thanks in advance!

If Cell $B$15=0, Hide Rows 16,17, and 18

If Cell $E$15=0, Hide Rows 19, 20, and 21

If Cell $H$15=0, Hide Rows 22, 23, and 24
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
open excel workbook
enter VBE (alt-F11)
in the project pane (left pane) , select your workbook project
dbl-click ThisWorkbook
in right pane (code area) paste the code below
save workbook.


Code:
Public bOn As Boolean

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

bOn = Range("B15") = 0
Rows("16:18").Select
Selection.EntireRow.Hidden = bOn


bOn = Range("E15") = 0
Rows("19:21").Select
Selection.EntireRow.Hidden = bOn


bOn = Range("H15") = 0
Rows("22:24").Select
Selection.EntireRow.Hidden = bOn

Range("A1").Select
End Sub
 
Upvote 0
open excel workbook
enter VBE (alt-F11)
in the project pane (left pane) , select your workbook project
dbl-click ThisWorkbook
in right pane (code area) paste the code below
save workbook.


Code:
Public bOn As Boolean

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

bOn = Range("B15") = 0
Rows("16:18").Select
Selection.EntireRow.Hidden = bOn


bOn = Range("E15") = 0
Rows("19:21").Select
Selection.EntireRow.Hidden = bOn


bOn = Range("H15") = 0
Rows("22:24").Select
Selection.EntireRow.Hidden = bOn

Range("A1").Select
End Sub
This is what it looks like, but won't run.. (exact paste) When I pasted your's, a macro window popped up with a macro name of a macro I already wrote called HIDDENTABS...so I created (tried to) HIDDEN ROWS. Perhaps this is my problem....any ideas? I know I'm missing something somewhere. Thanks!

Sub HIDDENROWS()

Public bOn As Boolean

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

bOn = Range("B15") = 0
Rows("16:18").Select
Selection.EntireRow.Hidden = bOn


bOn = Range("E15") = 0
Rows("19:21").Select
Selection.EntireRow.Hidden = bOn


bOn = Range("H15") = 0
Rows("22:24").Select
Selection.EntireRow.Hidden = bOn

Range("A1").Select
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

End Sub
 
Upvote 0
remove: Sub HIDDENROWS() and the bottom

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
End Sub

you cant have those there.
 
Upvote 0
I removed those. When I click on the Run Sub green arrow, I get a Macros Window. The only Macro option I have is for a previous code I wrote to hide tabs, HIDETABS. I feel I'm REAL CLOSE THANKS TO YOU. I've tried creating a HIDEROWS macro name, but that doesn't seem to work. What's should I do now with the Macros Window? (Yes, I'm a real novice at VBA code, I know you can tell.) Thanks again!
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,209
Members
453,022
Latest member
RobertV1609

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