Excel VBA - Hide All Rows where value = Active Cell Offset Cell Value?
<p>I have a spreadsheet laid out like so:</p>

<pre><code>A        B            C
12       Row1         Click to Hide
12       Row2         Click to Hide
5        Row3         Click to Hide
4        Row4         Click to Hide
12       Row5         Click to Hide
</code></pre>

<p>I am using the following vba code to try and hide all rows which share the same number (in Column A) as the activeCell Row which the user has clicked to hide.</p>

<pre><code>Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Not Intersect(ActiveCell, Range("C:C")) Is Nothing And ActiveCell.Value = "Click to Hide" Then


Dim Cell As Range

Application.ScreenUpdating = False

Range("A4").End(xlDown).Select


For Each Cell In Range(ActiveCell, "A4")
Cell.EntireRow.Hidden = ActiveCell.Offset(0, -2)

Next
Application.ScreenUpdating = True



End If

End Sub
</code></pre>

<p>So for instance, if a user clicks 'Click to Hide' in column C on Row1, all rows with the number 12 in column A should be hidden.</p>

<p>At the moment i am getting an error code, 1004 offset of object or range failed.
Please can someone show me where i am going wrong? Thanks in advance.</p>