Return 2nd non-blank value in a list (with example)

ANDIF

New Member
Joined
Apr 27, 2007
Messages
39
You all are awesome. I have one more question to solve so I can finish this project.

I came across this page: http://www.exceltip.com/st/Find_the...ank_cell_in_range_in_Microsoft_Excel/606.html

which shows how to return the value of the first non-blank cell in an array. That's great, but I now need to find the next value, and so on. In the example, I'd need to get "BBB" to come out of the formula.

My list has other blanks inserted throughout the array, so it would more closely resemble:
A1
AAA

BBB

CCC

Any ideas?
 
Last edited:

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Try:

=INDEX(A1:A10,SMALL(IF($A$1:$A$10<>"",ROW($A$1:$A$10)-ROW($A$1)+1),2))

which is an array formula and must be confirmed with CTRL+SHIFT+ENER (doing so correctly will result in Excel putting { }'s around your formula in the formula bar)

Changing the ,2 on the end to ,1 or ,3 will return the first or third non empty item in the range respectively.
 
Upvote 0
Try:

=INDEX(A1:A10,SMALL(IF($A$1:$A$10<>"",ROW($A$1:$A$10)-ROW($A$1)+1),2))

which is an array formula and must be confirmed with CTRL+SHIFT+ENER (doing so correctly will result in Excel putting { }'s around your formula in the formula bar)

Changing the ,2 on the end to ,1 or ,3 will return the first or third non empty item in the range respectively.

Looks like this will do it, as soon as I solve the merged cells problem. Thanks for your help!
 
Upvote 0
Is there any way to plug this equation into an IF statement?

Here's my problem: I'm looking up an array that can have a maximum of 4 values, so I use your equation with 1 through 4 as the last value. The array, however, can have less than 4 (or zero) values. When this is the case, the formula that doesn't have a value returns a #NUM! error.

I tried surrounding it with an IF statement that read "=IF(your equation=ISERROR,"",your equation)" but I get a #VALUE! error. Entering with CTRL SHIFT ENTER yields a #NAME? error.
 
Upvote 0
Is there any way to plug this equation into an IF statement?

Here's my problem: I'm looking up an array that can have a maximum of 4 values, so I use your equation with 1 through 4 as the last value. The array, however, can have less than 4 (or zero) values. When this is the case, the formula that doesn't have a value returns a #NUM! error.

I tried surrounding it with an IF statement that read "=IF(your equation=ISERROR,"",your equation)" but I get a #VALUE! error. Entering with CTRL SHIFT ENTER yields a #NAME? error.

Control+shift+enter...

=IF(COUNTIF($A$1:$A$10,"?*")>=2,INDEX(A1:A10,SMALL(IF($A$1:$A$10<>"",ROW($A$1:$A$10)-ROW($A$1)+1),2)),"")
 
Upvote 0
Control+shift+enter...

=IF(COUNTIF($A$1:$A$10,"?*")>=2,INDEX(A1:A10,SMALL(IF($A$1:$A$10<>"",ROW($A$1:$A$10)-ROW($A$1)+1),2)),"")

I appreciate the effort on this one - I learn something new every time I post here (what is "?*"?).

This isn't quite getting it done. If my array is empty, this works fine, but if I have:
A1
AAA
(blank)
BBB
(blank)
(blank)
(blank)
-end of array-

The last two formulas are still coming up with a #NUM! error :(
 
Upvote 0
Must be frustrating to be so good at this stuff and have people like me screw up the little stuff.

I finally discovered the logic. Thanks for the help!
 
Upvote 0
I lied - there is one more step after all. These equations have worked wonderfully for the majority of this project.

The last step: I'd like to be able to return the value in the left adjacent cell. So if I have

A, B
X, AAA


Y, BBB

The formula would look for AAA, then return X. The next formula would skip over AAA, find BBB, and return Y.
 
Upvote 0
I can get the value with a formula such as this:

=INDEX(A1:B5,MATCH(theTextIWant,B1:B5,0),1)

But this obviously can't accommodate the "find next" functionality of the previous formulas. This stuff is just too over my head for me to figure out on my own.
 
Upvote 0
I can get the value with a formula such as this:

=INDEX(A1:B5,MATCH(theTextIWant,B1:B5,0),1)

But this obviously can't accommodate the "find next" functionality of the previous formulas. This stuff is just too over my head for me to figure out on my own.

Well a little trial and error and I have it. I hope y'all can benefit from this.

My table looks like this (A1:B5):
X,AAA
,
,
,
Y,BBB

The formula for finding first, second and third values in column B and returning corresponding A values is:

=INDEX(A1:B5,MATCH(INDEX(B1:B5,(SMALL(IF($B$1:$B$5<>"",ROW($B$1:$B$5)-ROW($B$1)+1),1))),B1:B5,0),1)

That one returns the first value, it would look like this for the second:

=INDEX(A1:B5,MATCH(INDEX(B1:B5,(SMALL(IF($B$1:$B$5<>"",ROW($B$1:$B$5)-ROW($B$1)+1),2))),B1:B5,0),1)

Cheers!
 
Upvote 0

Forum statistics

Threads
1,216,160
Messages
6,129,215
Members
449,493
Latest member
JablesFTW

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