count rows down in column from blank to blank

Danny54

Active Member
Joined
Jul 3, 2019
Messages
295
Office Version
  1. 365
Platform
  1. Windows
is there a function that I can insert that will count the # of rows containing data, counting downward until finding a blank row?

im using a vba script that builds the data and I i could insert somekind of function if there is one (perhaps?)


the data looks like this


Article ID
Blank
4018073
4057115
4474419
4512486
4516033
4516065
Blank
4474419
4512486
4516033
4516065
Blank
4018073
4057115
4474419
4512486
4516033
4516065
Blank
4018073
4057115
4474419
4512486
4516033
4516065

<colgroup><col></colgroup><tbody>
</tbody>

<colgroup><col></colgroup><tbody>
</tbody>
When done

Article ID
6
4018073
4057115
4474419
4512486
4516033
4516065
4
4474419
4512486
4516033
4516065
6
4018073
4057115
4474419
4512486
4516033
4516065
6
4018073
4057115
4474419
4512486
4516033
4516065

<tbody>
</tbody>

<colgroup><col></colgroup><tbody>
</tbody>
 

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
How about
Code:
Sub Danny54()
    Dim Rng As Range
    For Each Rng In Range("A2:A" & Rows.Count).SpecialCells(xlConstants).Areas
        Rng.Offset(-1).Resize(1).Value = Rng.Count
    Next Rng
End Sub
 
Upvote 0
Thanks for the quick response.

What im looking to do is have the count value in each group counting downward

1. find the first blank
count the number of cells below until the next blank
insert that count into this blank cell

2 find the next blank cell and repeat the process of counting downward and inserting the count

I was looking for a formula that I could insert into the blank cells that would insert a downward count


Sample Data

3 <- this was a blank cell but was replaced with the # 3 since there are three rows before the next blank cell
a
a
a

b
b
b
b
b

c
c
c
c
 
Upvote 0
If the data is created by a macro, why no add my code to the end, rather than having a formula?
 
Upvote 0
I ran your code as a vbs script and got this. Perhaps I did something wrong.

Thanks for working with me



26
4512577
4514601
4516115
4018073
2463332
2979596
4512486
4516033
4516065
4512486
4516033
4516065
4022619
4512486
4516033
4516065
2526302
4512486
4516033
4516065

<colgroup><col></colgroup><tbody>
</tbody>
 
Upvote 0
ok, checked your code again. the blank cells have a interior color of green but contain no data. If i remove the color, your code works. any suggestion on making it work so i don't have to remove the color first?


Thanks
 
Upvote 0
a little more checking.

I tested the code after using the fill with no color button and then ran the macro where-as it failed to see the cell as blank.

If i copied a unused cell to the right into this colored cell and then tested, "Perfect".

So, what is really in this cell and can I check for it? All i can see is the color green.

Thanks
 
Upvote 0
Does this cure the problem?
Code:
Sub Danny54()
    Dim rng As Range
    With Range("A2", Range("A" & Rows.Count).End(xlUp))
        .Value = .Value
        For Each rng In .SpecialCells(xlConstants).Areas
            rng.Offset(-1).Resize(1).Value = rng.Count
        Next rng
    End With
End Sub
If not in a blank cell put
=CODE(A2)
Where A2 is one of the blank cells, what does it say?
 
Upvote 0
That worked. So i can understand, what does the .Value = Value do?

Thanks so much! I appreciate the help I get here. You folks are Super. I hope to someday give back as well.

Have a wonderful day.
 
Upvote 0
If you have a formula that returns "" & then copy paste as values you will get a Nullstring in those cells, the .Value=.Value simply makes them truly blank.
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,497
Members
448,967
Latest member
visheshkotha

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