Hiding Rows

rosaW

New Member
Joined
Aug 14, 2009
Messages
13
Hello,

I am trying to hide a different row on two different sheets (sheet 1 and sheet 2) whenever the value of a certain cell in sheet 1 is null.

So when cell "O$2" on sheet1 is null, i want cells ("$A$34:$I$34") to be hidden on sheet1 and cells ("$D$5:$H$5") to be hidden on sheet2.

What VBA code would i need to do this?
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
You could probably put something like this in Sheet1

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Len(Range("O$2")) = 0 Then
        Sheet1.Range("$A$34:$I$34").EntireRow.Hidden = True
        Sheet2.Range("$D$5:$H$5").EntireRow.Hidden = True
    End If
End Sub
 
Upvote 0
The rows still are not hidden. Am i missing something?

Currently when the value in $O$2 is null i get "#N/A" which is not a problem other than that i don't want it showing, in order that the end user does not get confused.
 
Upvote 0
Try wrapping whatever [formula?] is giving you the "#N/A" with the ISERROR() function and an If statement so that it returns you a blank cell instead of "#N/A".

If it's a formula that is giving you "#N/A", try something like:

=IF(ISERROR(your_formula),"",your_formula) ...and then employ the other code I posted.
 
Upvote 0
Thank you, that partially worked.
But this i what i have found to work perfect for one sheet:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Range("$O$2") = "" Then
Range("$A$34:$I$34").EntireRow.Hidden = True
Else
Range("$A$34:$I$34").EntireRow.Hidden = False
End If

End Sub

This code only applies for my current sheet (sheet1) i need sheet2 to also hide the row ("$D$5:$H$5").

How would i be able to include sheet2 in the code so that the rows on both sheets are deleted at the same time when the condition of ("$O$2") = "" ?
 
Upvote 0
Have you tried something like the following?

Code:
[B]Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Range("$O$2") = "" Then[/B]
[B]Range("$A$34:$I$34").EntireRow.Hidden = True[/B]
[B][COLOR=red]Sheet2.Range("$D$5:$H$5").EntireRow.Hidden = True[/COLOR][/B]
[B]Else[/B]
[B]Range("$A$34:$I$34").EntireRow.Hidden = False[/B]
[B]End If[/B]

[B]End Sub[/B]
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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