Trying to reference a date using a specific criteria.

jjwapp

New Member
Joined
Jul 14, 2019
Messages
1
Looking for a formula that allows me to find the date for the first value given >0.
For example, P/N 70032 want to find 7/29/2019 date.



P/N
Past Due
7/8/2019
7/15/2019
7/22/2019
7/29/2019
70025
30
0
0
0
0
70028
0
0
0
0
0
70032
0
0
0
0
172
70042
0
0
0
0
0

<tbody>
</tbody>
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

sijpie

Well-known Member
Joined
Nov 1, 2008
Messages
4,074
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I can't think of a combination of formulas to do this other than an inflexible list of nested IF() functions combined with OFFSET()

I have written a small UDF (user defined function) that will do it for you. It also has a restriction (as a UDF can't use the 'CurrentRegion' property of a range): The heading of the partnumber column has to be "P/N". If not then you will have to modify that in the macro.

Press the Alt-F8 key in Excel and choose 'New'. This will open the VBA editor. In the editor window (right empty pane) paste the function below.
Save your file as a macro enabled workbook.

Now you can use the function by typing into a cell: =getdate4pos( then click with the mouse on the partnumber and close the bracket. You will notice that ecxel shows the function as you type.

Code:
Function GetDate4Pos(rCell As Range) As Date
'///////////////////////////////////////////
'// Function to return date in top row of //
'// range with partnumbers in left column.//
'// Date returned is for first non-zero   //
'// cell to right of partnumber.          //
'// Top left cell of range should have    //
'// text "P/N"                            //
'// ------------------------------------- //
'// Usage: =GetDate4Pos(A5) where A5 will //
'// be a cell with partnumber in the left //
'// column.                               //
'///////////////////////////////////////////

    Dim vAr As Variant
    Dim i As Long, c As Long, j As Long, UB1 As Long, UB2 As Long
    Dim sPN As String
    
    Application.Volatile True
    sPN = rCell.Text
    For i = 1 To rCell.Row - 1
        If rCell.Offset(-i, 0) = "P/N" Then
            UB1 = rCell.Row - i
            Exit For
        End If
    Next i
    c = 1
    Do While Len(rCell.Offset(-i, c))
        c = c + 1
    Loop
    UB2 = c - 1
    
    For c = 1 To UB2 + 1
        If rCell.Offset(0, c) > 0 Then
            Exit For
        End If
    Next c
     GetDate4Pos = rCell.Offset(-i, c)
    
End Function
 
Upvote 0

Forum statistics

Threads
1,186,877
Messages
5,960,381
Members
438,472
Latest member
Nate J

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
Top