column variables

M

mahmon

I have databse of products, one colum contains text values for the colours
these products are, red, green , blue, etc. what functinocan tell me how many
colours are in the column? help please
 
M

mahmon

thanks, but my problem is that the colours are repeated and i dont want it to
count a colour twice
 
R

Ron Rosenfeld

I have databse of products, one colum contains text values for the colours
these products are, red, green , blue, etc. what functinocan tell me how many
colours are in the column? help please

If there are no blanks in your range:

=SUM(IF(FREQUENCY(MATCH(rng,rng,0),MATCH(rng,rng,0))>0,1))

If there may be blanks, then use the *array* formula:

=SUM(IF(FREQUENCY(IF(LEN(rng)>0,MATCH(rng,rng,0),""),IF(LEN(rng)>0,MATCH(rng,rng,0),""))>0,1))

To enter an *array* formula, after typing or pasting it into the cell, hold
down <ctrl><shift> while hitting <enter>.


--ron
 
M

mahmon

Thanks cant seem to get that to work dont know of its me, i am quite new to
excel. what do i put in place of rng? Wwhat i want to do is for excel to look
down the list and count the number of different colours without me having to
input any of the values in the function
 
R

Ron Rosenfeld

Thanks cant seem to get that to work dont know of its me, i am quite new to
excel. what do i put in place of rng? Wwhat i want to do is for excel to look
down the list and count the number of different colours without me having to
input any of the values in the function

For "rng" you substitute the range which you are testing. So if your data
(list of colors) is in C2:C1000, you would substitute C2:C1000 where I have
written "rng".

Alternatively, you could NAME that range, "rng" and then you would not have to
substitute anything.


--ron
 
M

mahmon

BRILLIANT IT WORKS! thanks for your help. one more question, how do then
cross reference to values in another column? i have a second coloumn that has
either a blank of the word 'selected' in it. how do i then count all the same
criteria but only if they are 'selected' ?
 
R

Ragdyer

Do you want to count all the "Reds" that have "selected" in the adjoining
column?
Enter the color you're looking for in C1, and try this:

=SUMPRODUCT((A1:A1000=C1)*(B1:B1000="selected"))
 
R

Ron Rosenfeld

BRILLIANT IT WORKS! thanks for your help.

You're welcome. Thank you for the feedback.


one more question, how do then
cross reference to values in another column? i have a second coloumn that has
either a blank of the word 'selected' in it. how do i then count all the same
criteria but only if they are 'selected' ?

If your Colors are in a range named "Colors" (or use the appropriate cell
reference); and your column that may or may not have "Selected" in it is in a
range named "Sel" then

with the color of interest in A1:

=SUMPRODUCT((A1=Colors)*(Sel="Selected"))


--ron
 
M

mahmon

not quite what i wanted to achieve, i've used your formula

=SUM(IF(FREQUENCY(IF(LEN(D17:D32)>0,MATCH(D17:D32,D17:D32,0),""),IF(LEN(D17:D32)>0,MATCH(D17:D32,D17:D32,0),""))>0,1))

to count the number of options in the column, what i want to do now is add
to this forula so that it filters out all the ones that dont have 'selected'
in an adjacent coloumn. but i dont want to define a colour of interest
 
R

Ron Rosenfeld

what i want to do now is add
to this forula so that it filters out all the ones that dont have 'selected'
in an adjacent coloumn. but i dont want to define a colour of interest

What exactly do you mean by "filters out"?

Assuming you mean it the same way as Excel uses the term, with your cursor in
the table, select Data/Filter/AutoFilter. Then click on the down arrow at the
"Selected" column heading and choose something like "non-Blanks" or Does Not
Equal Selected

If you mean something else, please define it.


--ron
 
M

mahmon

Dear Ron

okay here goes:

below is a simple version of what i want to achieve,
I have the formula now for the first one, but its the second one that i am
struggling with. i want to be able to enter data in the table as it grows and
the two formulas at the top update as you go. sorry if i was not clearer
before, and thanks for all your help so far

number of colour choices = 3 (this was your first formula, thankyou!)
number of colour choices of selected products = 2 (? how do we do this?)

part no colours selected
1 red no
2 red yes
3 blue no
4 green no
5 green yes
 
R

Ron Rosenfeld

Dear Ron

okay here goes:

below is a simple version of what i want to achieve,
I have the formula now for the first one, but its the second one that i am
struggling with. i want to be able to enter data in the table as it grows and
the two formulas at the top update as you go. sorry if i was not clearer
before, and thanks for all your help so far

number of colour choices = 3 (this was your first formula, thankyou!)
number of colour choices of selected products = 2 (? how do we do this?)

part no colours selected
1 red no
2 red yes
3 blue no
4 green no
5 green yes

OK that is more clear.

If there are no blank colors in your list, then:

Number of color choices:

=SUM(IF(FREQUENCY(MATCH(colours,colours,0),MATCH(colours,colours,0))>0,1))

Number of color choices only in the selected products

=SUM(IF(FREQUENCY(MATCH(colours,colours,0)*(selected="yes"),MATCH(colours,colours,0))>0,1))

If there could be blank choices in the list of colors, then (as
array-formulas):

Number of color choices:
=SUM(IF(FREQUENCY(IF(LEN(colours)>0,MATCH(colours,colours,0),""),
IF(LEN(colours)>0,MATCH(colours,colours,0),""))>0,1))

Number of color choices only in the selected products:
=SUM(IF(FREQUENCY(IF(LEN(colours)>0,MATCH(colours,colours,0)*(selected="yes"),""),
IF(LEN(colours)>0,MATCH(colours,colours,0),""))>0,1))


--ron
 
M

mahmon

thanks again ron
works good, only one problem, if there aren't any "yes" in the selected
column the formula returns a value of 1 instead of 0? any ideas

cheers

As soon as you start ot input 'selected' the values are correct from 1 upwards
 
M

mahmon

i have nod discovered that the eror works inthis way:

if there is a yes in one of each colour then the formula works correct,
otherwise it is 1 plus every time
 
R

Ron Rosenfeld

thanks again ron
works good, only one problem, if there aren't any "yes" in the selected
column the formula returns a value of 1 instead of 0? any ideas

cheers

As soon as you start ot input 'selected' t

Actually that's not true :-(( There are other instances where this second
formula is incorrect. Let me think about it for a bit.


--ron
 
R

Ron Rosenfeld

i have nod discovered that the eror works inthis way:

if there is a yes in one of each colour then the formula works correct,
otherwise it is 1 plus every time

There is also a situation where you will get a count of 2 instead of 1.

In any event, I will recommend an ultimately simpler approach for both
problems. However, if you need to distribute the workbook to others, there may
be an issue.

Go to http://xcell05.free.fr/ and download and install Longre's free add-in:
morefunc.xll

Then use the following formulas:

Number of color choices:

=COUNTDIFF(colours)

Number of color choices only in the selected products, use the *array* formula:

=COUNTDIFF(IF(selected="yes",colours),,FALSE)

(That last FALSE argument tells the COUNTDIFF function to NOT count the FALSE
results).


--ron
 
M

mahmon

sorted! now that was much easier, thank you very much for all your help ron,
yo are a legend of excel!

wayne
 
R

Ron Rosenfeld

sorted! now that was much easier, thank you very much for all your help ron,
yo are a legend of excel!

wayne

You're welcome. I'm glad we got it working for you. Thank you for the
feedback.


--ron
 
Top