VBA to hide a row in different worksheet

G

Guest

I need a VBA code to automatically hide or unhide a row in one sheet based
upon the value is a cell on another sheet.

Example:

If Sheet1, cell A1 = 0, then Sheet2, row 5 is hiden.
If Sheet1, cell A1 >0, then Sheet2, row 5 is visible.

Suggestions?
 
G

Guest

Try: will unhide if not 0 (blank or <> 0)

Sub HideRow()

If Worksheets("sheet1").Range("A1") = 0 Then
Worksheets("sheet2").Rows(5).EntireRow.Hidden = True
Else
Worksheets("sheet2").Rows(5).EntireRow.Hidden = False
End If

End Sub
 
G

Guest

for the row to automatically get hidden a Worksheet change Event need to be
added into the code. Install as follows

1) right click tab on bottom of worksheet labeled Sheet1.
2) Select view Code
3) Copy subroutine below and paste into VBA Code window.



Sub Worksheet_Change(ByVal Target As Range)

If (Target.Row = 1) And (Target.Column = 1) And _
(Target = 0) Then

Worksheets("sheet2").Rows(5).EntireRow.Hidden = True
Else
Worksheets("sheet2").Rows(5).EntireRow.Hidden = False
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top