I have a spreadsheet laid out like so:
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
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.
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
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.
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.
Range("A4").End(xlDown).Select- MacroMarcActiveCelluseTargetas the cell in whcih they click is passed to the sub. 2.Cell.EntireRow.Hidden = Cell.Value = Target.Offset(0, -2).value3.For Each Cell In Range("A4", Cells(Rows.Count,1).End(xlUp))- Scott Craner