Solved

Count unique cells

Posted on 2011-02-14
8
433 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel Question 17 15
Excel. How to get via VBA the last used row in a named dynamic range 10 38
Excel 2010:  Creating a "Yes" or "No" Pop-Up 20 44
formatting - number format 2 14
A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

832 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