Using Nested IF statements to Hide a row
<p>I have been attempting to hide a row on a spreadsheet based on two conditional target values in two target addresses. This works when I want it to check one target address, but not if I use two. I have not found the solution on this site. Here is the sample code:</p>

<pre><code>If (Target.Address = "$G$2") And (Target.Value = "Yes") Then
    If (Target.Address = "$G$3") And (Target.Value = "Yes") Then
        Rows("4").EntireRow.Hidden = True
    End If
End If
</code></pre>

<p>This works when I just use the first line:</p>

<pre><code>If (Target.Address = "$G$2") And (Target.Value = "Yes") Then
    Rows("4").EntireRow.Hidden = True
End If
</code></pre>

<p>But won't work when I put further conditions in. I'm not sure if this is a limitation with the .Hidden internal function, or if VBA doesn't like my nested IF statements.</p>

<p>I'd be grateful for any help,</p>

<p>Thanks.</p>

<p><strong>EDIT:</strong></p>

<p>I have solved my problem from the comments, I wasn't properly targeting two separate values, here is my fix.</p>

<pre><code>If (Target.Address = "$G$2") And (Target.Value = "Yes") Then
    If (Worksheets(1).Cells(3, 7).Value = "Yes") Then

        Rows("4").EntireRow.Hidden = True
    End If
End If
</code></pre>

<p>Thank you for help.</p>