RonnyRaygun
New Member
- Joined
- Jun 3, 2015
- Messages
- 6
Hi all,
I was recently given some very useful advice here with regard to hiding cells using VBA. The code looked like this:
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("H22").Value = "N" Then
Rows("23:27").EntireRow.Hidden = True
ElseIf Range("H22").Value = "Y" Then
Rows("23:27").EntireRow.Hidden = False
End If
End Sub
I now want to hide rows in "sheet 1" based on the value of a cell in, for example, "sheet 2". I thought this would not be a problem and attempted to do this by linking directly to Sheet 2, and then tried linking a cell in sheet 1 to the relevant cell in sheet 2, and use similar code to that above. However, neither worked. It works fine when I input the value directly but when the value in the cell comes from a link to another tab, it doesn't work.
This is the code I tried that doesn't work:
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("'Sheet 2'!B6").Value = "N" Then
Rows("23:27").EntireRow.Hidden = True
ElseIf Range("'Sheet 2'!B6").Value = "Y" Then
Rows("23:27").EntireRow.Hidden = False
End If
End Sub
Any ideas on what would work in this situation?
I was recently given some very useful advice here with regard to hiding cells using VBA. The code looked like this:
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("H22").Value = "N" Then
Rows("23:27").EntireRow.Hidden = True
ElseIf Range("H22").Value = "Y" Then
Rows("23:27").EntireRow.Hidden = False
End If
End Sub
I now want to hide rows in "sheet 1" based on the value of a cell in, for example, "sheet 2". I thought this would not be a problem and attempted to do this by linking directly to Sheet 2, and then tried linking a cell in sheet 1 to the relevant cell in sheet 2, and use similar code to that above. However, neither worked. It works fine when I input the value directly but when the value in the cell comes from a link to another tab, it doesn't work.
This is the code I tried that doesn't work:
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("'Sheet 2'!B6").Value = "N" Then
Rows("23:27").EntireRow.Hidden = True
ElseIf Range("'Sheet 2'!B6").Value = "Y" Then
Rows("23:27").EntireRow.Hidden = False
End If
End Sub
Any ideas on what would work in this situation?