Solved

Count unique cells

Posted on 2011-02-14
8
437 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
[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
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
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…

756 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