Solved

Count unique cells

Posted on 2011-02-14
8
432 Views
Last Modified: 2012-05-11
I have a table consisting of

Name | Company | Tel
Mr A | Giant Corp | 1234
etc...

I would like some vb to count the amount of unique values in the company column.
Starting from row 2 to whatever the last row with data is.

Kind regards,
Antonio
0
Comment
Question by:cbsbutler
8 Comments
 
LVL 17

Expert Comment

by:gtgloner
ID: 34888019
Have a look at this file:
Book1.xls
0
 
LVL 33

Expert Comment

by:jppinto
ID: 34888029
Why do you need to do it with a macro?! Can't you do it with a formula? You could use SUMPRODUCT() or SUMIFS():

http://excel-user.blogspot.com/2011/02/sumif-and-sumifs-functions.html
http://excel-user.blogspot.com/2009/10/sumproduct-sum-values-based-on.html

jppinto
0
 
LVL 17

Accepted Solution

by:
gtgloner earned 250 total points
ID: 34888050
...one little glitch in the previous file, use this instead:
Book1.xls
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 45

Assisted Solution

by:patrickab
patrickab earned 250 total points
ID: 34888939
cbsbutler,

I hope gtloner doesn't mind but I've used his file (attached) to show another way of doing it using a Collection.

Patrick
Sub uv()
Dim rng As Range
Dim celle As Range
Dim coll As New Collection

With Sheets("Sheet1")
    Set rng = Range(.Cells(2, "B"), .Cells(.Rows.Count, "B").End(xlUp))
End With

For Each celle In rng
    On Error Resume Next
    coll.Add celle, celle
Next celle

MsgBox "Number of unique entries in the Company column = " & coll.Count

End Sub

Open in new window

Copy-of-Book1-4-02.xls
0
 
LVL 17

Expert Comment

by:gtgloner
ID: 34889935
Don't worry Patrick, I'm not holding any patents here  : - )
0
 
LVL 45

Expert Comment

by:patrickab
ID: 34889992
gtgloner,

Thanks for that generous response.

Patrick
0
 
LVL 24

Expert Comment

by:broomee9
ID: 35221188
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now