A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
@José
So the 20 available (K2 + L2), become negative at column P (added demand thru month P = 25 - 20 initially available = -5)
Respectfully disagree. For me this becomes negative in column O:
Assuming you're OK …:
Range M1:AJ1 is named "HeaderMonths" with a sheet Scope
In a VBA Module
Option Explicit
Public Function WhenBelowZero(ByRef rngQty As Range, ByRef rngVal As Range) As String
'
Dim iQty As Integer
Dim iTemp As Integer
Dim vArray As Variant
Dim i As Integer
Dim strMonth As String
Application.Volatile (False)
iQty = rngQty.Value
vArray = Application.Transpose(rngVal.Value)
' ASSUMPTIONS: Qty and all values in range rngVal are numeric
' otherwise the function will return a #VALUE! error
For i = LBound(vArray) To UBound(vArray)
iTemp = iTemp + vArray(i, 1)
If iTemp > iQty Then Exit For
Next i
If i > UBound(vArray) Then strMonth = "N/A" _
Else strMonth = ActiveSheet.Range("HeaderMonths").Columns(i).Value
WhenBelowZero = strMonth
End Function
In I2: =WhenBelowZero(L2;M2:AJ2)
Sample available here