Share via

Loop Up (Step -1) to hide blank rows

Anonymous
2025-01-07T01:44:32+00:00

Working on hiding blank rows in range A49:A103 except 10.

Dim i as Integer

Have the following so far as I am debugging, but keep getting errors at the next i

Set rng = Range("A103:A49")     'I want to work upwards in my range from A103 to A49

.Range("49:103").EntireRow.Hidden = False

    If fCount < 45 Then     'fCount is a variable that counts the number of subfolders in a folder, this counts correctly

    BlankRows = 55 - fCount     'BlankRows if a variable that subtracts the number of folders from the 55 rows in the range.  This is how many blank rows there are in total

    For i = BlankRows To 10 Step -1     'I want to hide all of the blank rows from A103 working up towards A49, but want to leave 10 blank rows, and this is where I am missing something.  I am not too sure if I have the For i statement in the wrong order with the For Each cell in rng statement or something else...

        For Each cell In rng     \*\*\*

            If cell.Value = "" Then

                cell.EntireRow.Hidden = True

            Else

                cell.EntireRow.Hidden = False

            End If

    Next i

   Else

    'Unhide all rows, otherwise

    .Range("49:103").EntireRow.Hidden = False

   End If
Microsoft 365 and Office | Excel | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

HansV 462.6K Reputation points
2025-01-07T08:04:31+00:00

This should be sufficient:

    Range("49:103").EntireRow.Hidden = False
    If fCount < 45 Then
        Range(fCount + 59 & ":103").EntireRow.Hidden = True
    End If

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

0 additional answers

Sort by: Most helpful