Link to home
Start Free TrialLog in
Avatar of Classic1
Classic1Flag for Canada

asked on

Dynamically count blanks in Excel

Hi there,
I was wondering if anyone can help me out collegue stopped by and asked if there's a way to count the # of blanks after a populated row, jump out of the loop, do another subroutine, then jump back in to the loop again... User generated image
So what he would like to do is (in the screenshot example):
See 09-B0640, count the 1 blank, exit out of the loop, based on the # of blanks (this case 1), go throught the Case function...after that's processed, go on to 09-P0650, count the blanks, exit out to the Case function, etc...etc...

I've also posted his code...I tried editing it, and I think there's got to be a Do While loop there or something...but I didn't want butcher his code and all the time he spent on

If you can help us out, that would be awesome!!!


Dim ALastRow As Long
Dim RowCount As Long
Dim BlankCount As Long

ALastRow = Range("A" & Rows.Count).End(xlUp).Row + 1

    For RowCount = 11 To ALastRow
        If Range("A" & RowCount) <> "" Then 'If cell is not blank
            BlankCount = 1
            Range("C" & RowCount) = BlankCount
            BlankCount = 1
        Else 'If cell is blank
            BlankCount = BlankCount + 1
            Range("C" & RowCount - BlankCount + 1) = BlankCount
        End If
        Debug.Print BlankCount
        If BlankCount - 1 < 1 Then
            MsgBox "The Do Until loop made is complete."
        End If
        Exit For
    Next 'RowCount

    Select Case BlankCount
        Case 1
        Case 2
        Case 3
        Case 4
        Case 5
        Case 6
    End Select

Open in new window

Avatar of aikimark
Flag of United States of America image

it might be helpful to show us generateHTML1-6 code
This might help.

Assume Range A1:B15 (14 cells out of the 30 contain data)

Use the following function: =COUNTBLANK(A1:B15)
Avatar of StephenJR
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Classic1


Hey all,
Sorry for the non-response, I was out of the offiice the latter part of the week, and it was a holiday yesterday...
Thanks for your input, I've relayed the code to my co-worker, so hopefully, I'll get some feedback later today!!!

Much appreciated,
Hi StephenJR,
Sorry for the delay, I gave my co-worker 2 weeks or so to give me some feedback, and he hasn't gotten back to me...but looking @ the code itself, it looks like it does the trick...

Much appreciated,