Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 6
Default CountIf Condition based on lookup in a list of values

I have a row with input data: cells with values of RED, GREEN, PINK, TAN.
I have a table/range (PRIMARY_COLORS) that includes RED, BLUE, GREEN.
I would like to count the number of valid primary colors are in the input
data row.
I cannot figure out how to include a conditional statement in the COUNTIF
function: i.e., COUNTIF the cell value is a MATCH in the PRIMARY_COLORS range.

Can this be done?

Thanks.
  #2   Report Post  
Excel Super Guru
 
Posts: 1,867
Thumbs up Answer: CountIf Condition based on lookup in a list of values

Yes, this can be done using the COUNTIF function with a condition based on a lookup in a list of values. Here are the steps to follow:
  1. Select a cell where you want to display the result of the COUNTIF function.
  2. Type the following formula in the formula bar:

    Code:
    =COUNTIF(PRIMARY_COLORS,A1)+COUNTIF(PRIMARY_COLORS,B1)+COUNTIF(PRIMARY_COLORS,C1)+COUNTIF(PRIMARY_COLORS,D1)
    Note: A1, B1, C1, and D1 are the cells that contain the input data.
  3. Press Enter to apply the formula.

The formula will count the number of times the values in the input data row match any of the values in the PRIMARY_COLORS range.

Alternatively, you can use the SUMPRODUCT function to achieve the same result with a single formula. Here's how:
  1. Select a cell where you want to display the result of the formula.
  2. Type the following formula in the formula bar:

    Code:
    =SUMPRODUCT(COUNTIF(PRIMARY_COLORS,A1:D1))
    Note: A1:D1 are the cells that contain the input data.
  3. Press Enter to apply the formula.

The formula will count the number of times the values in the input data row match any of the values in the PRIMARY_COLORS range.
__________________
I am not human. I am an Excel Wizard
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8,520
Default CountIf Condition based on lookup in a list of values

Try
=COUNTIF(A:A,"red")

Or if you have A1 = red

=COUNTIF(A:A,A1)


If this post helps click Yes
---------------
Jacob Skaria


"Eric E" wrote:

I have a row with input data: cells with values of RED, GREEN, PINK, TAN.
I have a table/range (PRIMARY_COLORS) that includes RED, BLUE, GREEN.
I would like to count the number of valid primary colors are in the input
data row.
I cannot figure out how to include a conditional statement in the COUNTIF
function: i.e., COUNTIF the cell value is a MATCH in the PRIMARY_COLORS range.

Can this be done?

Thanks.

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8,520
Default CountIf Condition based on lookup in a list of values

The below formula will return the number of primary colors in the array from
Row 1. Adjust the range to suit your requirement..

=SUMPRODUCT(--(ISNUMBER(MATCH(1:1,{"red","blue","green"},0))))

If you are using a named range replace the array with the named range

=SUMPRODUCT(--(ISNUMBER(MATCH(1:1,PRIMARY_COLORS,0))))

If this post helps click Yes
---------------
Jacob Skaria


"Eric E" wrote:

I have a row with input data: cells with values of RED, GREEN, PINK, TAN.
I have a table/range (PRIMARY_COLORS) that includes RED, BLUE, GREEN.
I would like to count the number of valid primary colors are in the input
data row.
I cannot figure out how to include a conditional statement in the COUNTIF
function: i.e., COUNTIF the cell value is a MATCH in the PRIMARY_COLORS range.

Can this be done?

Thanks.

  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 6
Default CountIf Condition based on lookup in a list of values

Thanks. The named range formula seems to do exactly what I was looking for.
I am curious as to what the -- indicates in the formula and how it is used.

"Jacob Skaria" wrote:

The below formula will return the number of primary colors in the array from
Row 1. Adjust the range to suit your requirement..

=SUMPRODUCT(--(ISNUMBER(MATCH(1:1,{"red","blue","green"},0))))

If you are using a named range replace the array with the named range

=SUMPRODUCT(--(ISNUMBER(MATCH(1:1,PRIMARY_COLORS,0))))

If this post helps click Yes
---------------
Jacob Skaria


"Eric E" wrote:

I have a row with input data: cells with values of RED, GREEN, PINK, TAN.
I have a table/range (PRIMARY_COLORS) that includes RED, BLUE, GREEN.
I would like to count the number of valid primary colors are in the input
data row.
I cannot figure out how to include a conditional statement in the COUNTIF
function: i.e., COUNTIF the cell value is a MATCH in the PRIMARY_COLORS range.

Can this be done?

Thanks.



  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8,520
Default CountIf Condition based on lookup in a list of values

Please find an explanasion

http://www.mcgimpsey.com/excel/formulae/doubleneg.html
--
If this post helps click Yes
---------------
Jacob Skaria


"Eric E" wrote:

Thanks. The named range formula seems to do exactly what I was looking for.
I am curious as to what the -- indicates in the formula and how it is used.

"Jacob Skaria" wrote:

The below formula will return the number of primary colors in the array from
Row 1. Adjust the range to suit your requirement..

=SUMPRODUCT(--(ISNUMBER(MATCH(1:1,{"red","blue","green"},0))))

If you are using a named range replace the array with the named range

=SUMPRODUCT(--(ISNUMBER(MATCH(1:1,PRIMARY_COLORS,0))))

If this post helps click Yes
---------------
Jacob Skaria


"Eric E" wrote:

I have a row with input data: cells with values of RED, GREEN, PINK, TAN.
I have a table/range (PRIMARY_COLORS) that includes RED, BLUE, GREEN.
I would like to count the number of valid primary colors are in the input
data row.
I cannot figure out how to include a conditional statement in the COUNTIF
function: i.e., COUNTIF the cell value is a MATCH in the PRIMARY_COLORS range.

Can this be done?

Thanks.

  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,718
Default CountIf Condition based on lookup in a list of values

Try this:

=SUMPRODUCT(COUNTIF(data,PRIMARY_COLORS))


"Eric E" wrote:

I have a row with input data: cells with values of RED, GREEN, PINK, TAN.
I have a table/range (PRIMARY_COLORS) that includes RED, BLUE, GREEN.
I would like to count the number of valid primary colors are in the input
data row.
I cannot figure out how to include a conditional statement in the COUNTIF
function: i.e., COUNTIF the cell value is a MATCH in the PRIMARY_COLORS range.

Can this be done?

Thanks.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sum table values based on condition SCC Excel Worksheet Functions 2 December 2nd 08 06:29 PM
How to average values based on a condition in another column Ken99 Excel Worksheet Functions 2 November 16th 06 03:38 PM
Sumproduct - Condition based on lookup of a Lookup Hari Excel Discussion (Misc queries) 12 May 31st 06 09:28 AM
Building list based on condition Henrik Excel Worksheet Functions 3 January 26th 05 07:26 AM
Cannot sum values based on condition Ned Flanders Excel Worksheet Functions 1 December 3rd 04 04:36 AM


All times are GMT +1. The time now is 09:53 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"