G
Guest
Hi,
Jim Cone helped me with the code below a few months ago. It works great.
What it does:
It hides certain rows in Sheet2 If A1 in Sheet1 is a certain text word.
Question:
Is it possible to have more than one Target.Address?
Example: If A1="Apples" and B1="Red Delicious" Then hide the specified rows
in Sheet2.
The working code I have now for a single Target.Address:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then
With Worksheets("Sheet2")
..Rows("1:35").EntireRow.Hidden = False
If Target.Text = "Apples" Then
..Rows("10:10").EntireRow.Hidden = True
..Rows("20:20").EntireRow.Hidden = True
ElseIf Target.Text = "Pears" Then
..Rows("15:15").EntireRow.Hidden = True
..Rows("25:25").EntireRow.Hidden = True
ElseIf Target.Text = "Oranges" Then
..Rows("30:30").EntireRow.Hidden = True
..Rows("35:35").EntireRow.Hidden = True
Else
..Rows("12:12").EntireRow.Hidden = True
..Rows("16:16").EntireRow.Hidden = True
End If
End With
End If
End Sub
I can't find very much information on this Target.Address subject in my
stack of books.
I've tried different combinations but none of my own coding works so far.
Thanks for your time in reading my question.
Amy
Jim Cone helped me with the code below a few months ago. It works great.
What it does:
It hides certain rows in Sheet2 If A1 in Sheet1 is a certain text word.
Question:
Is it possible to have more than one Target.Address?
Example: If A1="Apples" and B1="Red Delicious" Then hide the specified rows
in Sheet2.
The working code I have now for a single Target.Address:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then
With Worksheets("Sheet2")
..Rows("1:35").EntireRow.Hidden = False
If Target.Text = "Apples" Then
..Rows("10:10").EntireRow.Hidden = True
..Rows("20:20").EntireRow.Hidden = True
ElseIf Target.Text = "Pears" Then
..Rows("15:15").EntireRow.Hidden = True
..Rows("25:25").EntireRow.Hidden = True
ElseIf Target.Text = "Oranges" Then
..Rows("30:30").EntireRow.Hidden = True
..Rows("35:35").EntireRow.Hidden = True
Else
..Rows("12:12").EntireRow.Hidden = True
..Rows("16:16").EntireRow.Hidden = True
End If
End With
End If
End Sub
I can't find very much information on this Target.Address subject in my
stack of books.
I've tried different combinations but none of my own coding works so far.
Thanks for your time in reading my question.
Amy