PC Review


Reply
Thread Tools Rate Thread

count unique values in a col

 
 
miek
Guest
Posts: n/a
 
      13th Aug 2008
I have the following code that looks at worksheet s1 and
counts the number of unique times it sees a passed varible,
and reports this value to worksheet s2
But it always returns with a zero. can someone help with the code?

Thxs
Dim Col_value as string

Col_value = "A"

Worksheets("S1").Activate
l_lastrow = Cells(Rows.Count, 1).End(xlUp).Row
l_ans = ActiveSheet.Evaluate("COUNTIF(" & Col_value & "1:" & Col_value &
l_lastrow & ", txt1)")
Worksheets("S2").Activate
Range("A1").Value = l_ans



Worksheet s1 {source data ws}

A
1 txt1
2 txt1
3 txt2

Worksheet s2 {results ws}

A
1 0
2
3
 
Reply With Quote
 
 
 
 
Lionel H
Guest
Posts: n/a
 
      13th Aug 2008
Hi miek,
replace:
l_ans = ActiveSheet.Evaluate("COUNTIF(" & Col_value & "1:" & Col_value &
l_lastrow & ", txt1)")
by:
l_ans = ActiveSheet.Evaluate("COUNTIF(" & Col_value & "1:" & Col_value &
l_lastrow & ", ""txt1"")")

regards,
Lionel

"miek" wrote:

> I have the following code that looks at worksheet s1 and
> counts the number of unique times it sees a passed varible,
> and reports this value to worksheet s2
> But it always returns with a zero. can someone help with the code?
>
> Thxs
> Dim Col_value as string
>
> Col_value = "A"
>
> Worksheets("S1").Activate
> l_lastrow = Cells(Rows.Count, 1).End(xlUp).Row
> l_ans = ActiveSheet.Evaluate("COUNTIF(" & Col_value & "1:" & Col_value &
> l_lastrow & ", txt1)")
> Worksheets("S2").Activate
> Range("A1").Value = l_ans
>
>
>
> Worksheet s1 {source data ws}
>
> A
> 1 txt1
> 2 txt1
> 3 txt2
>
> Worksheet s2 {results ws}
>
> A
> 1 0
> 2
> 3

 
Reply With Quote
 
miek
Guest
Posts: n/a
 
      13th Aug 2008
Ok that worked. however, If I replace ""txt1"" with a varible

s_in as string
s_in = "txt1"
l_ans = ActiveSheet.Evaluate("COUNTIF(" & Col_value & "1:" & Col_value &
l_lastrow & ", s_in)")

It still always returns a zero... what gives?

"Lionel H" wrote:

> Hi miek,
> replace:
> l_ans = ActiveSheet.Evaluate("COUNTIF(" & Col_value & "1:" & Col_value &
> l_lastrow & ", txt1)")
> by:
> l_ans = ActiveSheet.Evaluate("COUNTIF(" & Col_value & "1:" & Col_value &
> l_lastrow & ", ""txt1"")")
>
> regards,
> Lionel
>
> "miek" wrote:
>
> > I have the following code that looks at worksheet s1 and
> > counts the number of unique times it sees a passed varible,
> > and reports this value to worksheet s2
> > But it always returns with a zero. can someone help with the code?
> >
> > Thxs
> > Dim Col_value as string
> >
> > Col_value = "A"
> >
> > Worksheets("S1").Activate
> > l_lastrow = Cells(Rows.Count, 1).End(xlUp).Row
> > l_ans = ActiveSheet.Evaluate("COUNTIF(" & Col_value & "1:" & Col_value &
> > l_lastrow & ", txt1)")
> > Worksheets("S2").Activate
> > Range("A1").Value = l_ans
> >
> >
> >
> > Worksheet s1 {source data ws}
> >
> > A
> > 1 txt1
> > 2 txt1
> > 3 txt2
> >
> > Worksheet s2 {results ws}
> >
> > A
> > 1 0
> > 2
> > 3

 
Reply With Quote
 
Lionel H
Guest
Posts: n/a
 
      13th Aug 2008
I've not tested this, but I would expect the following to work:

l_ans = ActiveSheet.Evaluate("COUNTIF(" & Col_value & "1:" & Col_value &
l_lastrow & "," & s_in & ")")


"miek" wrote:

> Ok that worked. however, If I replace ""txt1"" with a varible
>
> s_in as string
> s_in = "txt1"
> l_ans = ActiveSheet.Evaluate("COUNTIF(" & Col_value & "1:" & Col_value &
> l_lastrow & ", s_in)")
>
> It still always returns a zero... what gives?
>
> "Lionel H" wrote:
>
> > Hi miek,
> > replace:
> > l_ans = ActiveSheet.Evaluate("COUNTIF(" & Col_value & "1:" & Col_value &
> > l_lastrow & ", txt1)")
> > by:
> > l_ans = ActiveSheet.Evaluate("COUNTIF(" & Col_value & "1:" & Col_value &
> > l_lastrow & ", ""txt1"")")
> >
> > regards,
> > Lionel
> >
> > "miek" wrote:
> >
> > > I have the following code that looks at worksheet s1 and
> > > counts the number of unique times it sees a passed varible,
> > > and reports this value to worksheet s2
> > > But it always returns with a zero. can someone help with the code?
> > >
> > > Thxs
> > > Dim Col_value as string
> > >
> > > Col_value = "A"
> > >
> > > Worksheets("S1").Activate
> > > l_lastrow = Cells(Rows.Count, 1).End(xlUp).Row
> > > l_ans = ActiveSheet.Evaluate("COUNTIF(" & Col_value & "1:" & Col_value &
> > > l_lastrow & ", txt1)")
> > > Worksheets("S2").Activate
> > > Range("A1").Value = l_ans
> > >
> > >
> > >
> > > Worksheet s1 {source data ws}
> > >
> > > A
> > > 1 txt1
> > > 2 txt1
> > > 3 txt2
> > >
> > > Worksheet s2 {results ws}
> > >
> > > A
> > > 1 0
> > > 2
> > > 3

 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      13th Aug 2008
l_ans = ActiveSheet.Evaluate("COUNTIF(" & Col_value & "1:" & Col_value &
l_lastrow & "," & s_in & ")")


--
__________________________________
HTH

Bob

"miek" <(E-Mail Removed)> wrote in message
news:644D7763-A4DA-4367-ABB3-(E-Mail Removed)...
> Ok that worked. however, If I replace ""txt1"" with a varible
>
> s_in as string
> s_in = "txt1"
> l_ans = ActiveSheet.Evaluate("COUNTIF(" & Col_value & "1:" & Col_value &
> l_lastrow & ", s_in)")
>
> It still always returns a zero... what gives?
>
> "Lionel H" wrote:
>
>> Hi miek,
>> replace:
>> l_ans = ActiveSheet.Evaluate("COUNTIF(" & Col_value & "1:" & Col_value &
>> l_lastrow & ", txt1)")
>> by:
>> l_ans = ActiveSheet.Evaluate("COUNTIF(" & Col_value & "1:" & Col_value &
>> l_lastrow & ", ""txt1"")")
>>
>> regards,
>> Lionel
>>
>> "miek" wrote:
>>
>> > I have the following code that looks at worksheet s1 and
>> > counts the number of unique times it sees a passed varible,
>> > and reports this value to worksheet s2
>> > But it always returns with a zero. can someone help with the code?
>> >
>> > Thxs
>> > Dim Col_value as string
>> >
>> > Col_value = "A"
>> >
>> > Worksheets("S1").Activate
>> > l_lastrow = Cells(Rows.Count, 1).End(xlUp).Row
>> > l_ans = ActiveSheet.Evaluate("COUNTIF(" & Col_value & "1:" &
>> > Col_value &
>> > l_lastrow & ", txt1)")
>> > Worksheets("S2").Activate
>> > Range("A1").Value = l_ans
>> >
>> >
>> >
>> > Worksheet s1 {source data ws}
>> >
>> > A
>> > 1 txt1
>> > 2 txt1
>> > 3 txt2
>> >
>> > Worksheet s2 {results ws}
>> >
>> > A
>> > 1 0
>> > 2
>> > 3



 
Reply With Quote
 
Lionel H
Guest
Posts: n/a
 
      13th Aug 2008
Which only goes to show you should test things first.
you also need to change
s_in = "txt1" to
s_in = """txt1"""

regards
L

"Lionel H" wrote:

> I've not tested this, but I would expect the following to work:
>
> l_ans = ActiveSheet.Evaluate("COUNTIF(" & Col_value & "1:" & Col_value &
> l_lastrow & "," & s_in & ")")
>
>
> "miek" wrote:
>
> > Ok that worked. however, If I replace ""txt1"" with a varible
> >
> > s_in as string
> > s_in = "txt1"
> > l_ans = ActiveSheet.Evaluate("COUNTIF(" & Col_value & "1:" & Col_value &
> > l_lastrow & ", s_in)")
> >
> > It still always returns a zero... what gives?
> >
> > "Lionel H" wrote:
> >
> > > Hi miek,
> > > replace:
> > > l_ans = ActiveSheet.Evaluate("COUNTIF(" & Col_value & "1:" & Col_value &
> > > l_lastrow & ", txt1)")
> > > by:
> > > l_ans = ActiveSheet.Evaluate("COUNTIF(" & Col_value & "1:" & Col_value &
> > > l_lastrow & ", ""txt1"")")
> > >
> > > regards,
> > > Lionel
> > >
> > > "miek" wrote:
> > >
> > > > I have the following code that looks at worksheet s1 and
> > > > counts the number of unique times it sees a passed varible,
> > > > and reports this value to worksheet s2
> > > > But it always returns with a zero. can someone help with the code?
> > > >
> > > > Thxs
> > > > Dim Col_value as string
> > > >
> > > > Col_value = "A"
> > > >
> > > > Worksheets("S1").Activate
> > > > l_lastrow = Cells(Rows.Count, 1).End(xlUp).Row
> > > > l_ans = ActiveSheet.Evaluate("COUNTIF(" & Col_value & "1:" & Col_value &
> > > > l_lastrow & ", txt1)")
> > > > Worksheets("S2").Activate
> > > > Range("A1").Value = l_ans
> > > >
> > > >
> > > >
> > > > Worksheet s1 {source data ws}
> > > >
> > > > A
> > > > 1 txt1
> > > > 2 txt1
> > > > 3 txt2
> > > >
> > > > Worksheet s2 {results ws}
> > > >
> > > > A
> > > > 1 0
> > > > 2
> > > > 3

 
Reply With Quote
 
miek
Guest
Posts: n/a
 
      13th Aug 2008
Thanks I'm in the clear.......for now!

"Lionel H" wrote:

> Which only goes to show you should test things first.
> you also need to change
> s_in = "txt1" to
> s_in = """txt1"""
>
> regards
> L
>
> "Lionel H" wrote:
>
> > I've not tested this, but I would expect the following to work:
> >
> > l_ans = ActiveSheet.Evaluate("COUNTIF(" & Col_value & "1:" & Col_value &
> > l_lastrow & "," & s_in & ")")
> >
> >
> > "miek" wrote:
> >
> > > Ok that worked. however, If I replace ""txt1"" with a varible
> > >
> > > s_in as string
> > > s_in = "txt1"
> > > l_ans = ActiveSheet.Evaluate("COUNTIF(" & Col_value & "1:" & Col_value &
> > > l_lastrow & ", s_in)")
> > >
> > > It still always returns a zero... what gives?
> > >
> > > "Lionel H" wrote:
> > >
> > > > Hi miek,
> > > > replace:
> > > > l_ans = ActiveSheet.Evaluate("COUNTIF(" & Col_value & "1:" & Col_value &
> > > > l_lastrow & ", txt1)")
> > > > by:
> > > > l_ans = ActiveSheet.Evaluate("COUNTIF(" & Col_value & "1:" & Col_value &
> > > > l_lastrow & ", ""txt1"")")
> > > >
> > > > regards,
> > > > Lionel
> > > >
> > > > "miek" wrote:
> > > >
> > > > > I have the following code that looks at worksheet s1 and
> > > > > counts the number of unique times it sees a passed varible,
> > > > > and reports this value to worksheet s2
> > > > > But it always returns with a zero. can someone help with the code?
> > > > >
> > > > > Thxs
> > > > > Dim Col_value as string
> > > > >
> > > > > Col_value = "A"
> > > > >
> > > > > Worksheets("S1").Activate
> > > > > l_lastrow = Cells(Rows.Count, 1).End(xlUp).Row
> > > > > l_ans = ActiveSheet.Evaluate("COUNTIF(" & Col_value & "1:" & Col_value &
> > > > > l_lastrow & ", txt1)")
> > > > > Worksheets("S2").Activate
> > > > > Range("A1").Value = l_ans
> > > > >
> > > > >
> > > > >
> > > > > Worksheet s1 {source data ws}
> > > > >
> > > > > A
> > > > > 1 txt1
> > > > > 2 txt1
> > > > > 3 txt2
> > > > >
> > > > > Worksheet s2 {results ws}
> > > > >
> > > > > A
> > > > > 1 0
> > > > > 2
> > > > > 3

 
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
Sum and count of unique values Piotr Microsoft Excel Misc 4 19th Feb 2011 01:10 PM
Count Unique Values but not Filtered or Hidden Values Lee Microsoft Excel Worksheet Functions 3 2nd Jun 2009 11:18 PM
Count unique values in one column if values in corresponding columnare null? allie357 Microsoft Excel Programming 1 7th Dec 2008 09:37 AM
Count unique values and create list based on these values =?Utf-8?B?dmlwYTIwMDA=?= Microsoft Excel Worksheet Functions 7 5th Aug 2005 01:17 AM
Count unique values Bmcosta Microsoft Excel Worksheet Functions 7 15th Jun 2004 09:31 PM


Features
 

Advertising
 

Newsgroups
 


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