LastCell

G

Guest

I want to loop through rows first to make sure they are all unhidden, then I
want to hide rows that have "yes" in a cell. This doesn't work because the
xlCellTypeLastCell goes to the last visible cell. So if the last cell had
"yes" in it, it would have been hidden and my code won't unhide it. I dont'
know how to fix it.

Hope I explained this.

Thanks,

Private Sub CAT()
Dim i As Long

For i = 1 To ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row

If Cells(i, 2).Rows(i).Hidden = True Then
Cells(i, 2).Rows(i).Hidden = False

ElseIf Cells(i, 2).Value = "Yes" Then
Rows(i).EntireRow.Hidden = True
End If

Next i
End Sub
 
P

PCLIVE

I'm sure there are other ways, but you can add this to the top of your code
to unhide all columns and rows.

With Cells
.Rows.Hidden = False
.Columns.Hidden = False
End With
 
G

Guest

Try it in two steps:

1. make sure ALL rows are unhidden:
Cells.EntireRow.Hidden = False

2. run the logic to hide what you want
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top