Simple Question for an Expert

BrettOlbrys1

Board Regular
Joined
May 1, 2018
Messages
139
Office Version
  1. 365
Platform
  1. Windows
I know this is probably simple, but I am having trouble. I simply want to return the first value in a row that is not blank. So if X=blank:

X X 4 X 5 6 1 X 5
X 3 X 5 X X X X X

For the 1st row, the returned value would be 4
For the 2nd row, the returned value would be 3

What is the formula I need to use to return the 1st non-blank value in a row?

Thanks
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Welcome to the MrExcel board!

A couple of choices.
- The column K formula confirmed with Ctrl+Shift+Enter, not just Enter then copied down, or
- The column L formula that does not require the special confirmation.

Excel Workbook
ABCDEFGHIJKL
14561544
23533
First non-blank
 
Upvote 0
you can do a vba function and use that

in vba editor, put in this function:

Code:
function find_first(Search_Rng as Range)
Dim rng as Range

For each rng in Search_Rng
     If rng <>"" then
           find_first = rng.value
           exit function
     end if
next rng

End function

Then, in your spreadsheet, just type in formula =find_First(Range you want to apply) and this should return the first value in that range that's not blank.
 
Last edited:
Upvote 0
Worked perfectly, thank you.


Welcome to the MrExcel board!

A couple of choices.
- The column K formula confirmed with Ctrl+Shift+Enter, not just Enter then copied down, or
- The column L formula that does not require the special confirmation.

First non-blank

ABCDEFGHIJKL

<tbody>
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]1[/TD]

[TD="align: right"]4[/TD]

[TD="align: right"]5[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"]1[/TD]

[TD="align: right"]5[/TD]

[TD="align: right"]4[/TD]
[TD="align: right"]4[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]2[/TD]

[TD="align: right"]3[/TD]

[TD="align: right"]5[/TD]

[TD="align: right"]3[/TD]
[TD="align: right"]3[/TD]

</tbody>

Spreadsheet Formulas
CellFormula
K1{=INDEX(A1:I1,MATCH(TRUE,A1:I1<>"",0))}
L1=INDEX(A1:I1,MATCH(TRUE,INDEX(A1:I1<>"",0),0))

<tbody>
</tbody>
Formula Array:
Produce enclosing
{ } by entering
formula with CTRL+SHIFT+ENTER!

<tbody>
</tbody>


Excel tables to the web >> Excel Jeanie HTML 4
 
Upvote 0
you can do a vba function and use that

in vba editor, put in this function:

Code:
function find_first(Search_Rng as Range)
Dim rng as Range

For each rng in Search_Rng
     If rng <>"" then
           find_first = rng.value
           exit function
     end if
next rng

End function
The OP apparently wanted a formula solution, but I thought you might find the following alternate UDF, a one-liner, to be of interest...
Code:
[table="width: 500"]
[tr]
	[td]Function FindFirst(rng As Range)
  FindFirst = Split(Application.Trim(Join(Application.Index(rng.Value, 1, 0))) & " ")(0)
End Function[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0
The OP apparently wanted a formula solution, but I thought you might find the following alternate UDF, a one-liner, to be of interest...
Code:
[table="width: 500"]
[tr]
	[td]Function FindFirst(rng As Range)
  FindFirst = Split(Application.Trim(Join(Application.Index(rng.Value, 1, 0)))[COLOR="#FF0000"][B] & " "[/B][/COLOR])(0)
End Function[/td]
[/tr]
[/table]
Is there any need for the red text?
Have to hope the first non-blank cells doesn't contain a space character. ;)
 
Upvote 0
It makes the function print out the empty string ("") if the whole row is empty (otherwise the function prints out a #VALUE ! error).
Fair enough, though an error may be preferred - as the formula suggestions that were accepted produce an error in that circumstance.


Because if the first non-empty cell contains "The cat sat on the mat" the function as-is returns "The", rather than the requested "the first value in a row that is not blank".
I do note that the sample data was purely numeric so the situation might not arise for the OP, but made the comment in case the data might be varied or another reader might wish to use the function in other circumstances.
 
Upvote 0
The OP apparently wanted a formula solution, but I thought you might find the following alternate UDF, a one-liner, to be of interest...
Code:
[TABLE="width: 500"]
<tbody>[TR]
[TD]Function FindFirst(rng As Range)
  FindFirst = Split(Application.Trim(Join(Application.Index(rng.Value, 1, 0))) & " ")(0)
End Function[/TD]
[/TR]
</tbody>[/TABLE]

That's interesting. I'll have to look at what it's doing. Thanks
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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