First cell with value in a range

Tanya Addison

New Member
Joined
Jul 10, 2003
Messages
45
how do i find the position of the first cell that contains a value in a range ?
the range is a single row of approximately 20 cells. Some cells will blank
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
In VBA?

Code:
Sub Test()
    If Not IsEmpty(Range("A1")) Then
        MsgBox Range("A1").Address(False, False) & " is the first cell"
    Else
        MsgBox Range("A1").End(xlDown).Address(False, False) & " is the first cell"
    End If
End Sub
 
Upvote 0
amazing!
i wish i could understand whats behind this formula...
i mean, why "1" as the match value?
and why do you add 0 to the index array?
 
Upvote 0
Can you use something like this? =index(match(true,a3:t3<>"",0)). You need to us Cntrl+Shift+Enter. Hope this helps.
 
Upvote 0
amazing!
i wish i could understand whats behind this formula...
i mean, why "1" as the match value?
and why do you add 0 to the index array?

In...

=MATCH(1,INDEX((A3:T3<>"")+0,1,0),0)

The INDEX((A3:T3<>"")+0,1,0) bit unfolds something like this:

INDEX({FALSE,FALSE,TRUE,FALSE,...}+0,1,0)

>>

INDEX({0,0,1,0,...},1,0) [ FALSE+0 >> 0; TRUE+0 >> 1 ]

{0,0,1,0,...} stands as it were for a range, 1 for the first row of that range, and 0 for all columns of that range.

The surrounding MATCH picks out the column of the first occurrence of 1 in the foregoing calculated reference. Note that this is still an array-processing formula, but it needs not the control+shift+enter signal because the array is already calculated by the INDEX expression.

For the record, MATCH(TRUE,A3:T3>0,0) is equivalent and requires the array-processing signal.
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,196
Members
449,072
Latest member
DW Draft

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