How to compare every second column cell to a specific value?
I have a problem in Excel 2007. I need to compare one value - letter "C" -开发者_JS百科 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
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.
I could try something like this:
=IF(OR(LEFT(A2,1)<>"C",LEFT(B2,1)<>"C",LEFT(C2,1)<>"C",LEFT(D2,1)<>"C",LEFT(E2,1)<>"C"),"Not Valid","Valid")
Col_A Col_B Col_C Col_D Col_E VALIDATION
C 434 C 435 C 436 C 437 C 435 Valid
C 435 C 436 C 437 C 438 C 436 Valid
C 436 C 437 C 438 C 439 C 437 Valid
C 437 B 438 C 439 C 440 C 438 Not Valid
C 438 C 439 C 440 C 441 C 439 Valid
C 439 C 440 C 441 B 442 C 440 Not Valid
C 440 C 441 C 442 C 443 C 441 Valid
C 441 C 442 C 443 C 444 C 442 Valid
C 442 C 443 C 444 C 445 C 443 Valid
C 443 B 444 C 445 C 446 B 444 Not Valid
With this you don't need to add Columns, because validates every string
in the same formula.
精彩评论