mongoose00318
mongoose00318

Reputation: 131

Error: Application-defined or object-defined when trying to hide row

I am trying to hide rows in a table based on certain criteria. I have the code working to find the cells and now I am trying to hide the other rows but when I do I get the following error:

"Run-time error: '1004': Application-defined or object-defined error"

Here is my code:

'Intiansiate objects and setup variables
Dim tbl As ListObject
Dim c As Range
Dim colStartDate As Range
Dim FoundDate As Date
'Set object/variable values
Set tbl = ActiveWorkbook.Worksheets(1).ListObjects("Table1")

With tbl
    'Search "Start Date" (Col2), top to bottom, searching for the first cell with a color index of 35 and the "End Date" (Col3) which has an index color of anything other than 35
    Set colStartDate = .ListColumns("start date").DataBodyRange
    For Each c In colStartDate.Cells
        If c.Interior.ColorIndex = 35 And c.Offset(0, 1).Interior.ColorIndex <> 35 Then
            FoundDate = c.Value
            Exit For
        End If
    Next c

    For Each c In colStartDate.Cells
        If Not c.Hidden = True Then
            If Not c.Value >= FoundDate Then
                c.Hidden = True
            End If
        End If
    Next c
End With

MsgBox FoundDate

Upvotes: 0

Views: 223

Answers (1)

BigBen
BigBen

Reputation: 49998

Per the Range.Hidden docs:

The specified range must span an entire column or row.

Use c.EntireRow.Hidden = True.

Upvotes: 3

Related Questions