have column of years (numeric), would like tocount how many by decade.

mr_techie

New Member
Joined
Apr 27, 2012
Messages
8
Hi,

I am new to VBA, an thus may be a trivial question, but I haven;t founf an answer, yet.

I have a column of years, 1921 to 2011, and would like to find out hoe many are in each decade, ie >=1920 and <=1929, for each decade.

the column is in numeric form, but could be easily converted to text.

any help would be appreciated.

thanks in advance!!
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Hi and welcome.

Try something like this...

Code:
[color=darkblue]Dim[/color] count [color=darkblue]As[/color] [color=darkblue]Long[/color], decade [color=darkblue]As[/color] [color=darkblue]Long[/color]

[color=darkblue]For[/color] decade = 1920 [color=darkblue]To[/color] 2019 [color=darkblue]Step[/color] 10

    count = WorksheetFunction.CountIf(Range("A:A"), ">=" & decade) - WorksheetFunction.CountIf(Range("A:A"), ">" & decade + 9)
    MsgBox count, , "Count for " & decade & "s"
    
[color=darkblue]Next[/color] decade
 
Upvote 0
Thanks!

Haven't tried it yet, but looks feasible.

don't know if I was clear on this detail, but column is in random order, not numeric.
 
Upvote 0
the previous offfering doesn't work, with either text or numbers in the column.

the column has a year, as text, in each row, from 1929 to 2011. I want to count hw many are in each decade, >=1929 and <=1929, for each decade.

thought I could use c--COUNTIF, but it's not working.

here;s a sample of the column

<table border="0" cellpadding="0" cellspacing="0" width="35"><colgroup><col style="mso-width-source:userset;mso-width-alt:1280;width:26pt" width="35"> </colgroup><tbody><tr style="height:15.0pt" height="20"> <td class="xl65" style="height:15.0pt;width:26pt" height="20" width="35">1987</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl65" style="height:15.0pt" height="20">1968</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl65" style="height:15.0pt" height="20">1984</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl65" style="height:15.0pt" height="20">2007</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl65" style="height:15.0pt" height="20">2006</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl65" style="height:15.0pt" height="20">1982</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl65" style="height:15.0pt" height="20">1968</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl65" style="height:15.0pt" height="20">2001</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl65" style="height:15.0pt" height="20">1988</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl65" style="height:15.0pt" height="20">1981</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl65" style="height:15.0pt" height="20">1993</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl65" style="height:15.0pt" height="20">1991</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl65" style="height:15.0pt" height="20">2004</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl65" style="height:15.0pt" height="20">2001</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl65" style="height:15.0pt" height="20">1979</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl65" style="height:15.0pt" height="20">1979</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl65" style="height:15.0pt" height="20">1979</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl65" style="height:15.0pt" height="20">1979</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl65" style="height:15.0pt" height="20">1979</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl65" style="height:15.0pt" height="20">2010</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl65" style="height:15.0pt" height="20">2010</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl65" style="height:15.0pt" height="20">1973</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl65" style="height:15.0pt" height="20">2004</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl65" style="height:15.0pt" height="20">2005</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl65" style="height:15.0pt" height="20">1947</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl65" style="height:15.0pt" height="20">2003</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl65" style="height:15.0pt" height="20">1978</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl65" style="height:15.0pt" height="20">1980</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl65" style="height:15.0pt" height="20">1979</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl65" style="height:15.0pt" height="20">1999</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl65" style="height:15.0pt" height="20">1996</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl65" style="height:15.0pt" height="20">2011</td> </tr> <tr style="height:15.0pt" height="20"> <td class="xl65" style="height:15.0pt" height="20">2009</td> </tr> </tbody></table>
 
Upvote 0
wound up doing 'brute-force- method -- tested for eaxh tear, then did sum for each 10 years. it works anyway :):)
 
Upvote 0
this really shouldn't be that difficult...

Excel Workbook
ABC
1198719200
2196819300
3198419401
4200719500
5200619602
6198219708
7196819806
8200119904
9198820009
10198120103
1119932020
121991
132004
142001
151979
161979
171979
181979
191979
202010
212010
221973
232004
242005
251947
262003
271978
281980
291979
301999
311996
322011
332009
Sheet1
 
Upvote 0
thanks! interesting ...
now I need that in VBA :cool:- have about 700 records to search.

on a similar note, have a column od media types - DVD, DVD(5), DVD(50) - and was trying to copy matching rows to a sheet. DVD works, but can't seem to be able to find the other two cases. I am actually looking at DVD(?) and DVD(??). I have tried IF THEN and CASE SELECT, but while they find DVD, neither finds the other cases.
 
Upvote 0
No one has said why the countif function isn't working on a column of years, I am trying to do the same thing count the number of years that fall in a decade, have tried using a wildcard but just get zero back. COUNTIF(SINGLES!Q3:Q601,"196?") I have also tried * instead of the ? but still returns a zero. I have tried formatting the column on years as numeric, text and general and all return zero.

Any ideas?
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,715
Members
448,985
Latest member
chocbudda

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