Unsure how to write a loop which intentially skips particualr rows

EwEn999

New Member
Joined
Dec 3, 2018
Messages
27
Hi, I've got the below code to behave as expected, but I'd like the loop to skip pre determined rows if its possible. :confused:

Code:
Sub HidingRowsWhenBlank()
Dim r 'row
    For r = 4 To 62 'skip rows 20 to 31 and rows 41 to 52
        If WorksheetFunction.CountA(Range((Cells(r, 3)), (Cells(r, 33)))) = 0 Then
        Rows(r).Select
        Selection.EntireRow.Hidden = True
    End If
Next r
End Sub

Thanks in adavance
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
you could do something like this:
Code:
Sub HidingRowsWhenBlank()
Dim r 'row
    For r = 4 To 62 'skip rows 20 to 31 and rows 41 to 52
        If WorksheetFunction.CountA(Range((Cells(r, 3)), (Cells(r, 33)))) = 0 Then
        Rows(r).Select
        Selection.EntireRow.Hidden = True
    End If
    If r = 19  or r =40 Then
        r = r + 13
    End If
Next r
End Sub
 
Last edited:
Upvote 0
Rows 19 & 40 will get checked.
 
Upvote 0
@RSpin
I can see what you are trying to do, but rows 19 and 40 need to be checked as well
apologise for my earlier reply, ive used a variation of what you suggested and it worked, its not as neat and tidy as I was hoping for but it still works.

Code:
HidingRowsWhenBlank()
Dim r 'row
    For r = 4 To 62 'skip rows 20 to 31 and rows 41 to 52
        If r = 20 Then
            r = 32
        End If
        If r = 41 Then
            r = 53
        If WorksheetFunction.CountA(Range((Cells(r, 3)), (Cells(r, 33)))) = 0 Then
        [LEFT][COLOR=#333333][FONT=monospace]Rows(r).Select
        Selection.EntireRow.Hidden = True
[/FONT][/COLOR][/LEFT]
    End If
Next r
End Sub
 
Last edited:
Upvote 0
my apologies. looking back I did my math wrong. I believe it should have been
Code:
R= R+12
in the original formula. That way when r = 19 or 40, then your code will run, then the addition will happen and finally the "Next r" will happen and you should be good to go.

but what you have should work just fine as well.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,785
Messages
6,174,535
Members
452,570
Latest member
Ron1970

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top