Count Rows above each blank Row

Page0727

New Member
Joined
Nov 2, 2018
Messages
20
I am trying to work out how I can count rows containing data above multiple blank rows. I then need it to place count number in each blank row. I'm not sure how to do this at all. Any help would be much appreciated.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
I am trying to work out how I can count rows containing data above multiple blank rows. I then need it to place count number in each blank row. I'm not sure how to do this at all. Any help would be much appreciated.

Is it possible there are 2 or more consecutive blank row?
If not, try this:

Code:
[FONT=lucida console][COLOR=Royalblue]Sub[/COLOR] a1082810a()
[I][COLOR=seagreen]'https://www.mrexcel.com/forum/excel-questions/1082810-count-rows-above-each-blank-row.html[/COLOR][/I]
[COLOR=Royalblue]Dim[/COLOR] n [COLOR=Royalblue]As[/COLOR] [COLOR=Royalblue]Long[/COLOR], k [COLOR=Royalblue]As[/COLOR] [COLOR=Royalblue]Long[/COLOR], i [COLOR=Royalblue]As[/COLOR] [COLOR=Royalblue]Long[/COLOR]
[COLOR=Royalblue]Dim[/COLOR] va [COLOR=Royalblue]As[/COLOR] [COLOR=Royalblue]Variant[/COLOR]

n = Range([COLOR=brown]"A"[/COLOR] & Rows.count).[COLOR=Royalblue]End[/COLOR](xlUp).Row
va = Range([COLOR=brown]"A1:A"[/COLOR] & n + [COLOR=crimson]1[/COLOR])

[COLOR=Royalblue]For[/COLOR] i = [COLOR=crimson]1[/COLOR] [COLOR=Royalblue]To[/COLOR] UBound(va, [COLOR=crimson]1[/COLOR]) - [COLOR=crimson]1[/COLOR]
    k = [COLOR=crimson]0[/COLOR]
        [COLOR=Royalblue]Do[/COLOR]
        k = k + [COLOR=crimson]1[/COLOR]
        i = i + [COLOR=crimson]1[/COLOR]
        [COLOR=Royalblue]Loop[/COLOR] [COLOR=Royalblue]Until[/COLOR] va(i, [COLOR=crimson]1[/COLOR]) = [COLOR=brown]""[/COLOR]
    Cells(i, [COLOR=brown]"A"[/COLOR]) = k
[COLOR=Royalblue]Next[/COLOR]

[COLOR=Royalblue]End[/COLOR] [COLOR=Royalblue]Sub[/COLOR][/FONT]
 
Upvote 0
This is awesome, but how would I ignore the header?

If the header is at row 1 then:

Change this line:
Code:
For i = 1 To UBound(va, 1) - 1

to:
Code:
For i = 2 To UBound(va, 1) - 1
 
Upvote 0

Forum statistics

Threads
1,214,636
Messages
6,120,664
Members
448,976
Latest member
sweeberry

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