Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count the Number of Each Itam in a List with VBA-Excel 1

Status
Not open for further replies.

Psycho69

Technical User
Feb 4, 2008
3
US
I have been using VBA with Excel basically to solve one problem at a time over about 5 years. I use it so little that I forget how to construct the code without resorting to trial and error and looking for solutions by others. Recently, I was given a ginormous assignment to process a huge database, some of which has to pass through Excel for processing. Lucky me, I get to write the code to do the Excel parts.

What I get is list of 3000-5000 rows of data that is delimited. It parses out into 13 columns and then I have to line up which elements belong in each column and so some cells are empty. I have this part figured out an done.

Next I have to take each column and count the number of common elements. The number of elements can vary from 1 to very many. I have located 2 ways that work. One is to sort the column and then count and delete each element. That works but my column is gone, but I can work around it by by moving a copy of each column to a new sheet for counting. The count is what is needed anyway.

The second way is a pivot table which also works great, but I have never used a pivot table and have no idea what purpose it serves.

What I would really like to do is count each column in place and put the results somewhere on the page or add anew sheet with the summarized data. The columns will have "holes" or blank cells, so the "counter" has to ignore blank cells or count them as blank cells. Also, before anything begins, I get the top cell of the list and the bottom cell of the list for looping for the total number of items. That value plus the number of columns is a constant for each list I receive. The elements in the list are always variable.
 



"The second way is a pivot table which also works great, but I have never used a pivot table and have no idea what purpose it serves."

Well, you found ONE of the purposes.

A PivotTable is just a summary report. You found a way of summaring the number of occurrances of a value. As you use it, you'll find more ways that it can help you get answers like this one super quick!

A PivotTable seems to be THE tool for the situation that you described.

Skip,

[glasses]Did you hear what happened when the OO programmer lost his library?...
He's now living in OBJECT poverty![tongue]
 
Thank you Skip,

I am now plowing through the chapter on "Pivot Tables" in Mr. Excel. Guess I'll have to learn something new, but if it works, it will save me a lot of time later.
 




Once you get comfortable with PTs, you'll never turn back. You can get aggregations in SECONDS, change on the fly. good stuff!

Skip,

[glasses]Did you hear what happened when the OO programmer lost his library?...
He's now living in OBJECT poverty![tongue]
 
I hope those "aggregations"are not damaged brain cells that lead to dementia? :-<

I've tried it on several tables and it seems to give me the correct output quick and dirty. The only problem is the "form" that is created is not self intuitive. Also, I think I have too new of a version of Excel so the book I am using at work is outdated. I have an Excel-VBA 2003 book at home so I will have to look at that tonight.

Thanks again.

ron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top