PC Review


Reply
Thread Tools Rate Thread

Count unique instances of text in column

 
 
medirate
Guest
Posts: n/a
 
      7th May 2009
I have a column of text where I need to count the unique values. The column
of text is in another worksheet called Dist. The column of data may look
like this:

24509
13450
24509
18709
24509
13450

I have no idea what the column of data may contain beforehand, so I can't do
a count of "24509", but I need the result to look like this:

24509 3
13450 2
18709 1

Any suggestions?

Thanks!


 
Reply With Quote
 
 
 
 
mcwilsong
Guest
Posts: n/a
 
      7th May 2009
Hi Medirate,

I found this in Excel's help. Is this what you were looking for?

Count the number of unique values by using a filter
You can use the Advanced Filter to extract the unique values from a column
of data and paste them to a new location. Then you can use the ROWS function
to count the number of items in the new range.

Ensure that the first row in the column has a column header.
On the Data menu, point to Filter, and then click Advanced Filter.
In the Advanced Filter dialog box, click Copy to another location.
If the range that you are counting is not already selected, delete any
information in the List range box and then click the column (or select the
range) that contains your data.
In the Copy to box, delete any information in the box or click in the box,
and then click a blank column where you want to copy the unique values.
Select the Unique records only check box, and click OK.
The unique values from the selected range are copied to the new column.

In the blank cell below the last cell in the range, enter the ROWS function.
Use the range of unique values that you just copied as the argument. For
example, if the range of unique values is B1:B45, then enter:
=ROWS(B1:B45)


"medirate" wrote:

> I have a column of text where I need to count the unique values. The column
> of text is in another worksheet called Dist. The column of data may look
> like this:
>
> 24509
> 13450
> 24509
> 18709
> 24509
> 13450
>
> I have no idea what the column of data may contain beforehand, so I can't do
> a count of "24509", but I need the result to look like this:
>
> 24509 3
> 13450 2
> 18709 1
>
> Any suggestions?
>
> Thanks!
>
>
>

 
Reply With Quote
 
Per Jessen
Guest
Posts: n/a
 
      7th May 2009
Hi

Look at this, output will be in Sheet1:

Sub AAA()
Dim TargetSh As Worksheet
Dim DestSh As Worksheet
Dim FilterRange As Range
Set TargetSh = Worksheets("Dist")
Set DestSh = Worksheets("Sheet1") ' Change to suit
FirstRow = 1 ' HeaderRow
TargetCol = "A" ' Change to suit
LastRow = TargetSh.Range(TargetCol & Rows.Count).End(xlUp).Row
Set FilterRange = TargetSh.Range(TargetCol & FirstRow, _
TargetSh.Range(TargetCol & LastRow))
FilterRange.AdvancedFilter Action:=xlFilterInPlace, _
Unique:=True
FilterRange.SpecialCells(xlCellTypeVisible).Copy _
Destination:=DestSh.Range("A1")
CellCount = FilterRange.SpecialCells(xlCellTypeVisible).Cells.Count
TargetSh.ShowAllData
DestSh.Range("B2").FormulaR1C1 = "=COUNTIF(Dist!R2C1:R7C1,RC[-1])"
DestSh.Range("B2").AutoFill Destination:=DestSh.Range _
("B2:B" & CellCount), Type:=xlFillDefault
End Sub

Regards,
Per

On 7 Maj, 01:10, "medirate" <medir...@aol.com> wrote:
> I have a column of text where I need to count the unique values. The column
> of text is in another worksheet called Dist. The column of data may look
> like this:
>
> 24509
> 13450
> 24509
> 18709
> 24509
> 13450
>
> I have no idea what the column of data may contain beforehand, so I can'tdo
> a count of "24509", but I need the result to look like this:
>
> 24509 * *3
> 13450 * *2
> 18709 * *1
>
> Any suggestions?
>
> Thanks!


 
Reply With Quote
 
medirate
Guest
Posts: n/a
 
      7th May 2009
Not exactly. I need to accomplish this withouot user input. Bascially the
data for each worksheet will be imported from a text file. I have this set
up so that all they have to do is click the Refresh Data button. At that
point, the new text is imported, and I need this function to calculate the
unique values from a column in the newly imported text.


"mcwilsong" <(E-Mail Removed)> wrote in message
news:70497874-9430-4F79-AB7F-(E-Mail Removed)...
> Hi Medirate,
>
> I found this in Excel's help. Is this what you were looking for?
>
> Count the number of unique values by using a filter
> You can use the Advanced Filter to extract the unique values from a column
> of data and paste them to a new location. Then you can use the ROWS

function
> to count the number of items in the new range.
>
> Ensure that the first row in the column has a column header.
> On the Data menu, point to Filter, and then click Advanced Filter.
> In the Advanced Filter dialog box, click Copy to another location.
> If the range that you are counting is not already selected, delete any
> information in the List range box and then click the column (or select the
> range) that contains your data.
> In the Copy to box, delete any information in the box or click in the box,
> and then click a blank column where you want to copy the unique values.
> Select the Unique records only check box, and click OK.
> The unique values from the selected range are copied to the new column.
>
> In the blank cell below the last cell in the range, enter the ROWS

function.
> Use the range of unique values that you just copied as the argument. For
> example, if the range of unique values is B1:B45, then enter:
> =ROWS(B1:B45)
>
>
> "medirate" wrote:
>
> > I have a column of text where I need to count the unique values. The

column
> > of text is in another worksheet called Dist. The column of data may look
> > like this:
> >
> > 24509
> > 13450
> > 24509
> > 18709
> > 24509
> > 13450
> >
> > I have no idea what the column of data may contain beforehand, so I

can't do
> > a count of "24509", but I need the result to look like this:
> >
> > 24509 3
> > 13450 2
> > 18709 1
> >
> > Any suggestions?
> >
> > Thanks!
> >
> >
> >



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Display a list of unique values from a column with multiple instances jaggy Microsoft Excel Discussion 4 23rd May 2009 04:12 AM
How do I count the # of unique occurences of a text in a column? =?Utf-8?B?Um9iIEthaXNlcg==?= Microsoft Excel Worksheet Functions 10 21st Nov 2007 09:16 PM
how can I count unique instances of repeating data on a report Bob Quintal Microsoft Access 5 5th Jul 2007 02:12 PM
count unique instances based on two columns omnicrondelicious@gmail.com Microsoft Excel Worksheet Functions 9 27th May 2007 01:49 AM
Count a unique instances of a record jonefer Microsoft Access Reports 2 4th Dec 2003 05:26 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:36 PM.