Simple "If" Function - HELP

J

James8309

Hi, Everyone

Let me first explain what I am trying to achieve very briefly.

1. If A1 = "E" and A2 >A3 and A3<A4 then return "ABC"
= > I know I can do this by using " if(and(A1="E",A2>A3,
A3>A4),"ABC",""))

However! However!!

2. if A1 = "E" stays same... except next criterias are different and
yes there are 95 of them. I just thought that it is painful to use
"And" function to hook up all the three criterias.
i.e. a) A1 = "E", A2<A3, A3=A4, then return "DEF" etc etc
b) A1 = "E", A2=A3, A4>A3 then return "XXX" etc etc etc etc x 95
times.

Is there any other way to lock that A1 = "E" ?? so I don't have to
type "And(A1 = "E", etc etc )" 95 times???

Should I be using VBA instead? Would that be easier?

Thank you for your help in advance!
 
G

GB

James8309 said:
Hi, Everyone

Let me first explain what I am trying to achieve very briefly.

1. If A1 = "E" and A2 >A3 and A3<A4 then return "ABC"
= > I know I can do this by using " if(and(A1="E",A2>A3,
A3>A4),"ABC",""))

However! However!!

2. if A1 = "E" stays same... except next criterias are different and
yes there are 95 of them. I just thought that it is painful to use
"And" function to hook up all the three criterias.
i.e. a) A1 = "E", A2<A3, A3=A4, then return "DEF" etc etc
b) A1 = "E", A2=A3, A4>A3 then return "XXX" etc etc etc etc x 95
times.

Is there any other way to lock that A1 = "E" ?? so I don't have to
type "And(A1 = "E", etc etc )" 95 times???

Should I be using VBA instead? Would that be easier?

Thank you for your help in advance!

Hmm, interesting. So, if I have understood you correctly, your cell will
contain 95 If statements all linked together with &s? You don't explain if
there is any logic in the way those ABCs and DEFs are generated. I can't
remember the maximum number of characters in a cell, but hopefully that
won't be a problem. However, actually generating the 95 If statements will
be (almost) impossible to do accurately by hand. I suggest that you create a
spreadsheet specifically to generate the formula you want to use.

An alternative is to use a scoring system, so A1 = A scores 1, through to
A1=Z scores 26. Also A2<A3 scores 100, A2= A3 scores 200, etc. (The scores
are done so that each combination is bound to give a unique value.) Then add
the 3 scores and use a lookup tables.
 
J

James8309

Hmm, interesting. So, if I have understood you correctly, your cell will
contain 95 If statements all linked together with &s? You don't explain if
there is any logic in the way those ABCs and DEFs are generated. I can't
remember the maximum number of characters in a cell, but hopefully that
won't be a problem. However, actually generating the 95 If statements will
be (almost) impossible to do accurately by hand. I suggest that you createa
spreadsheet specifically to generate the formula you want to use.

An alternative is to use a scoring system, so A1 = A scores 1, through to
A1=Z scores 26. Also A2<A3 scores 100, A2= A3 scores 200, etc. (The scores
are done so that each combination is bound to give a unique value.) Then add
the 3 scores and use a lookup tables.- Hide quoted text -

- Show quoted text -


Firstly, Thanks for your help!


Basically,
1. I have Range A1 to A850 containing alphabets. They are almost
distributed.
i.e. A1 might be B, A2 might be Z ... etc

2. Column B, C, D and E contains numbers.

3. Each alphabet in Range("A1:A850") has different families.
i.e. A will have A110, A220, A33, A555 etc depending on relationship
between Column B,C,D and E

Example, lets say A group
A111 = B>C, C = D, D<E
A222 = B<C, C<>D, D>E
etc etc etc

if I was to code this conditions in column F it would be something
like this
"
if(and(A1="A",B>C,C=D,D<E),"A111",if(and(A1="A",B<C,C<>D,D>E),"A222",if
if if if if if etc etc etc

This is why I will end up with over 90 "if" & "And" statement in one
cell. I don't even know if it is possible. As you can see in every if
statement, there is condition A1="A". I just didn't know how to lock
it or make it common to all other statements.

Thanks again!
 
P

Pete_UK

Do the 3 digits which follow the letter all follow the same consistent
rules? i.e. does 1xx always mean B>C and 2xx mean B<C (and presumably
0xx mean B=C)? And does x1x always mean C=D, x2x mean C<>D? And does
xx1 always mean D<E and xx2 mean D>E?

There is some inconsistency here, but I'm just going off your example.

You basically have 4 possible outcomes of comparing two adjacent
columns:

B=C, B>C, B<C, and B<>C (if you count this)

and similarly with the other adjacent columns C to D and D to E. So
you could allocate a specific code to these conditions, i.e. 0, 1, 2
and 3 and thus calculate the overall code, something like:

=A1 & IF(B1=C1,0,IF(B1>C1,1,2)) & IF(C1=D1,0,IF(C1>D1,1,2)) &
IF(D1=E1,0,IF(D1>E1,1,2))

and then copy this down. This is more consistent, but does not check
for C<>D and thus does not tie up exactly with your example (but then
there were only two combinations shown !!). This will give you an
output like "A111", or "A020" depending on the conditions being met -
you might need to play about with it a bit to get your exact
combinations.

Hope this helps.

Pete
 
P

Pete_UK

A few other thoughts - if you don't have a purely consistent coding
system (i.e. the combinations for the "B" family might be different
than the "A" family etc), then you can use the approach I have
suggested to give you an intermediate code, and also have a lookup
table of those intermediate codes and the actual codes and use VLOOKUP
to translate into the "real" codes.

Hope this helps.

Pete
 
J

James8309

A few other thoughts - if you don't have a purely consistent coding
system (i.e. the combinations for the "B" family might be different
than the "A" family etc), then you can use the approach I have
suggested to give you an intermediate code, and also have a lookup
table of those intermediate codes and the actual codes and use VLOOKUP
to translate into the "real" codes.

Hope this helps.

Pete











- Show quoted text -

Pete, Thanks mate! You are a champ! :D
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top