Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
DAVID
 
Posts: n/a
Default find first nonzero value in column

I have two columns A and B. Column A contains ascending numbers from 1 to
100, while Column B contains arbitrary values. I am looking for the function
that finds the first nonzero value in column B (going from first to last row)
and then returns the value of column A of the same row. (This request might
be posted twice).

David
  #2   Report Post  
David Jessop
 
Posts: n/a
Default

Hi,

Try

Function NonZero(FirstCol As Range, SecondCol As Range)
Dim i As Integer
NonZero = Error

If (FirstCol.Rows.Count = SecondCol.Rows.Count) Then
For i = 1 To FirstCol.Rows.Count
If (SecondCol.Cells(i, 1) < 0) Then
NonZero = FirstCol.Cells(i, 1)
Exit For
End If
Next i
End If
End Function

This allows you to have separate ranges. The only thing you might want to
change is the return value if nothing is found.

HTH,

David Jessop

"DAVID" wrote:

I have two columns A and B. Column A contains ascending numbers from 1 to
100, while Column B contains arbitrary values. I am looking for the function
that finds the first nonzero value in column B (going from first to last row)
and then returns the value of column A of the same row. (This request might
be posted twice).

David

  #3   Report Post  
Ola
 
Posts: n/a
Default

Hi,

On solution is:
=SMALL(IF(B1:B100<0,A1:A100),1)
Hold down Ctrl+Shift and then hit Enter to confirm the formula.

Ola

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
find rows for unique data in 1 column and different data in other. Dot Majewski Excel Discussion (Misc queries) 1 January 21st 05 12:23 AM
find first nonzero value in column DAVID Excel Worksheet Functions 5 January 11th 05 03:31 AM
find first nonzero value in column DAVID Excel Worksheet Functions 0 January 10th 05 01:11 PM
find LAST match in column Pantryman Excel Worksheet Functions 1 November 5th 04 04:05 PM
Find AVG/MIN of a Column, excluding 0's and NULL's? JT Excel Worksheet Functions 3 November 4th 04 06:15 PM


All times are GMT +1. The time now is 02:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"