views:

37

answers:

1

Hi!

I have a problem in Excel 2007. I need to compare one value - letter "C" - to a range of cells that are on one row. The problem is that the values should be in every other cell.

So if I have a row like this - C 434 C 324 C 3453 - it should say in a cell in the end - OK And if I have a row like this - C 22 B 665 C 8877 - it should say - error as not all are C's.

Should be done as a formula not VBA.

So the question is is it possible to check if every other cell in a row ( a range ) contains a value C and output a value based on that.

PS! There are too many rows to do it by hand like this (pseudocode) =IF(AND(A1="C"; A3="C");"ok";"error")

Thanks

+2  A: 

Here's something you can try. It requires the use of some extra cells, but it should get the job done. Let's say you start with this data:

Col_A  Col_B  Col_C  Col_D  Col_E  Col_F  Col_G  Col_H  Col_I
C 434  xxx    C 435  xxx    C 436  xxx    C 437  xxx    C 435
C 435  xxx    C 436  xxx    C 437  xxx    C 438  xxx    C 436
C 436  xxx    C 437  xxx    C 438  xxx    C 439  xxx    C 437
C 437  xxx    B 438  xxx    C 439  xxx    C 440  xxx    C 438
C 438  xxx    C 439  xxx    C 440  xxx    C 441  xxx    C 439
C 439  xxx    C 440  xxx    C 441  xxx    B 442  xxx    C 440
C 440  xxx    C 441  xxx    C 442  xxx    C 443  xxx    C 441
C 441  xxx    C 442  xxx    C 443  xxx    C 444  xxx    C 442
C 442  xxx    C 443  xxx    C 444  xxx    C 445  xxx    C 443
C 443  xxx    B 444  xxx    C 445  xxx    C 446  xxx    B 444

... let's say "Col_A" is in cell A1, and the actual data starts in cell A2. Select cell A13 and enter the following formula:

=IF(OR(LEFT(A2)="C", MOD(COLUMN(A2),2)=0),1,0)

Now click A13 and drag to the right to extend it to I13. Drag that whole range down to A22:I22. You should have a field of ones and zeros in those cells now.

Next, click cell K2 and enter the formula:

=IF(PRODUCT(A13:I13),"Valid","Not valid!")

Click cell K2 and drag it down to extend it to K11.

That's it; you can hide the block of cells with all the ones and zeros if you want.

Disclaimer: only tested in OO Calc. Should work in Excel too though.

no
Thanks, needed to modify it a bit to make it do more what I wanted but it was a god-sent help :)
Marten