VBA count Blank Cells

Finalfight40

Active Member
Joined
Apr 24, 2018
Messages
273
Office Version
  1. 365
Platform
  1. Windows
Hi All

I am looking for a little advice as i expect i am going to get a spreadsheet soon with exported data and i wanted to get a head start on a piece of VBA that i'm not aware how to do:

So i have the example data below as follows:

ABCD
1NameDateTime InTime Out
2John##################
3##################
4#############
5Jamie###############
6#################
7Bob##############
8Polly###############
9##################
10#############
11###############
12#################
13Jeff################
14################

<tbody>
</tbody>

So there would be 1 thing i was hoping to get advice on.

Lets say my active cell is currently on John. How could i determine the number of blank cells below John in Column A before i reached Jamie. (So for this example 2)

Also this would need to work for an example like Bob where it would return 0 blank cells.
 
Last edited:

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Hi Finalfight40,

You do not need VBA to count blank cells. Yes it can be done with VBA, but I suggest using worksheet functions when they are properly needed, and VBA for other automation needs. And a combination of worksheet functions and VBA at times.

For example: to find if a cell is blank, you can use the LEN() function to check if what is in it has a zero length thus it will be empty.

Now knowing what you want to do with these blank cells, other than counting them, will help in developing a more productive reply.

Hope this helps.
 
Upvote 0
Mayble

Code:
Sub countcells()
Dim lr As Long
Dim nr As Long
Dim cr As Long
If ActiveCell = "" Then
    MsgBox ("No name selected")
    Exit Sub
End If
lr = Cells(Rows.Count, "A").End(xlUp).Row
cr = ActiveCell.Row
nr = ActiveCell.End(xlDown).Row
If nr <= lr Then
    countc = nr - cr - 1
    MsgBox ("The number of blank cells between names is " & countc)
Else
    MsgBox ("Selected name is the last name no next name")
End If
 
Upvote 0
Hi Phil

Unfortunately this would need to be done via VBA because it will be put into a macro to perform various other calculations.
 
Upvote 0
Scott

That works perfectly and is exactly what i am looking for.

Thank you
 
Upvote 0

Forum statistics

Threads
1,214,622
Messages
6,120,576
Members
448,972
Latest member
Shantanu2024

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