Avatar of Classic1
Flag for Canada asked on

Dynamically count blanks in Excel

Hi there,
I was wondering if anyone can help me out here...my 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... Screenshot example
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 it...lol.

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

Microsoft ExcelVB Script

Avatar of undefined
Last Comment

8/22/2022 - Mon

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)

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

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,
Your help has saved me hundreds of hours of internet surfing.

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,