Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# Count unique cells

Posted on 2011-02-14
Medium Priority
455 Views
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
Question by:cbsbutler
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 17

Expert Comment

ID: 34888019
Have a look at this file:
Book1.xls
0

LVL 33

Expert Comment

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

gtgloner earned 1000 total points
ID: 34888050
...one little glitch in the previous file, use this instead:
Book1.xls
0

LVL 45

Assisted Solution

patrickab earned 1000 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
Next celle

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

End Sub
``````
Copy-of-Book1-4-02.xls
0

LVL 17

Expert Comment

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

LVL 45

Expert Comment

ID: 34889992
gtgloner,

Thanks for that generous response.

Patrick
0

LVL 24

Expert Comment

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

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to usâ€¦
###### Suggested Courses
Course of the Month7 days, 22 hours left to enroll