Increment x in Col A ONLY IF adjacent Col B cell NOT Blank

powerjak

New Member
Joined
Jan 28, 2003
Messages
29
Should be simple, but I'm in a brain-lock. I want to increment by 1, a value in Column A successive row cells, but only IF the adjacent cell in Column B is NOT blank. IF Column B cell ISBLANK(), then Column A cell is to also be blank.

Example:

A B
1 text
2 text
3 text
4 text

5 text
6 text

7 text

I've tried a number of nested IFs using different Fx evaluations of Col B, but so far, nothing I've tried gets me a result that I can replicate down all row cells of Col A to get the results of the example above without any error results.

I'm sure it'll turn out to be a "head slapper" when one of you bright people provide the assist to untwist my brain ... and I'll certainly appreciate the help!
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Re: Increment x in Col A ONLY IF adjacent Col B cell NOT Bla

powerjak said:
Should be simple, but I'm in a brain-lock. I want to increment by 1, a value in Column A successive row cells, but only IF the adjacent cell in Column B is NOT blank. IF Column B cell ISBLANK(), then Column A cell is to also be blank.

Example:

A B
1 text
2 text
3 text
4 text

5 text
6 text

7 text

I've tried a number of nested IFs using different Fx evaluations of Col B, but so far, nothing I've tried gets me a result that I can replicate down all row cells of Col A to get the results of the example above without any error results.

I'm sure it'll turn out to be a "head slapper" when one of you bright people provide the assist to untwist my brain ... and I'll certainly appreciate the help!

In A1 enter: 1

if B1 is not blank.

In A2 enter & copy down:

=IF(B2="","",LOOKUP(9.99999999999999E+307,$A$1:A1)+1)

or

=IF(ISBLANK(B2),"",LOOKUP(9.99999999999999E+307,$A$1:A1)+1)
 
Upvote 0
another solution:
In A1 enter 1
In A2 enter =IF(B2<>"",MAX($A$1:A1)+1,"") and copy down
Book1
ABCD
11text
22text
33text
44text
5 
65text
76text
8 
97text
Sheet1
 
Upvote 0
Works GREAT - New Wrinkle Just Came Up Though

I've just been informed that the formula should NOT increment based on TWO evaluations. That is, if a cell in Col B is blank, do not increment [as currently provided by your =IF(B2<>"",MAX($A$1:A1)+1,"") formula], however, if Col B is NOT blank, then ALSO DO NOT increment the value in Col A if the word "deceased" is found anywhere in a text string located in Col D.
 
Upvote 0
Using my first example, in A2 enter
=IF(AND(B2<>"",ISERROR(SEARCH("decreased",D2))=TRUE),MAX($A$1:A1)+1,"")
and copy down

Edit:
oops, I thought you said "decreased" if it should be "deceased" you will need to change that in my formula
 
Upvote 0
Re: Works GREAT - New Wrinkle Just Came Up Though

powerjak said:
I've just been informed that the formula should NOT increment based on TWO evaluations. That is, if a cell in Col B is blank, do not increment [as currently provided by your =IF(B2<>"",MAX($A$1:A1)+1,"") formula], however, if Col B is NOT blank, then ALSO DO NOT increment the value in Col A if the word "deceased" is found anywhere in a text string located in Col D.
Book5
ABCD
10
2IDXY
3 Vort is deceased
41wqa
52tra
6 ytaThe deceased...
73otua
84ewa
952
1066/2/2004
11 
Sheet1


A1 must house a 0.

A3, copied down:

=IF((B3="")+ISNUMBER(SEARCH("deceased",D3)),"",LOOKUP(9.99999999999999E+307,$A$1:A2)+1)
 
Upvote 0
WOW - I am impressed! Thanks!!!!

Travis, Aladin, you guys are simply great.

Both of your approaches work exactly as needed and I've already completed the needed patch. And as I suspected, there was a bit of head-slapping involved at this end, as my initial approach was very close to Travis', although I got myself brain-locked on a fine point that his help made very clear.

Aladin, your approach I would never have gotten to myself ... and I wouldn't have considered using a lockup with the largest number that Excel can recognize (9.99999999999999E+307) as part of the approach. Nevertheless, it is clever and works perfectly as well.

Bottomline -- It's a crappy day when you don't learn something new ... and clearly, I can learn an amazing amount of stuff from people like yourselves. Thanks again. You both really made my day!
 
Upvote 0
Re: WOW - I am impressed! Thanks!!!!

powerjak said:
...I wouldn't have considered using a lockup with the largest number that Excel can recognize (9.99999999999999E+307) as part of the approach. Nevertheless, it is clever and works perfectly as well...

Might look foreign, even clever. But the real reason for it is speed.
 
Upvote 0
Hi Aladin, just curious, but given that i was headed the way of Travis' formula, is there a speed advantage in using ISNUMBER(SEARCH... over perhaps COUNTIF(, eg

=IF((B3="")+COUNTIF(D3,"*deceased*"),"",LOOKUP(9.99999999999999E+307,$A$1:A2)+1)
 
Upvote 0
KenWright said:
Hi Aladin, just curious, but given that i was headed the way of Travis' formula, is there a speed advantage in using ISNUMBER(SEARCH... over perhaps COUNTIF(, eg

=IF((B3="")+COUNTIF(D3,"*deceased*"),"",LOOKUP(9.99999999999999E+307,$A$1:A2)+1)

It seems IsNumber/Search has a slight edge over CountIf... Tested with a range of 30 cells using FastExcel, 5 runs altogether. Maybe it isn't that surprising since Search is a tuned up text function. Needs a more serious test though.
 
Upvote 0

Forum statistics

Threads
1,226,464
Messages
6,191,182
Members
453,646
Latest member
BOUCHOUATA

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top