VBA Code to Count and Total the Number of Blank Rows

Eshleman

New Member
Joined
Mar 11, 2016
Messages
3
Hi.

I'm looking for VBA code that counts and totals the number of nonblank rows between data in column F of my spreadsheet. The issue that I am having is that the number of rows is not consistent. For example, the data looks like this:



F1 $1,200
F2 blank
F3 $128
F4 blank
F5 $105
F6 $100
F7 $200
F8 blank

The spreadsheet is very large. The above data is just an example. So, in column G, I need to see a 1 in cell G1. I need to see a 1 in G3. And, I need to see a 3 in cell G5. For cells that are blank in column F, the respective cells in column G should also be blank.
 

Some videos you may like

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

skywriter

Well-known Member
Joined
Feb 15, 2014
Messages
1,642
Here's the code and the results of running the code.
Code:
Sub Eshleman()
Dim j
    For Each j In Range("F1", Range("F" & Rows.Count).End(xlUp)).SpecialCells(2).Areas
        j(1, 2).Value = j.Rows.Count
    Next j
End Sub

Excel Workbook
FG
1$1,2001
2
3$1281
4
5$1053
6$100
7$200
Sheet1
 

Eshleman

New Member
Joined
Mar 11, 2016
Messages
3
Thank you, skywriter. This code is exactly what I need. I really appreciate your help!
 

Watch MrExcel Video

Forum statistics

Threads
1,122,418
Messages
5,596,024
Members
414,037
Latest member
Roamingsmile

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
Top