Rather tortuous, but I think it gets you there.
Sub x()
Dim r As Long, r1 As Long, r2 As Long
Sheets("Summary").Activate
With Application
If Range("C3") <> "" And Range("C4") <> "" Then
r1 = .Match(Range("C3"), Sheets("Data").Columns(1), 0)
r2 = .Match(Range("C4"), Sheets("Data").Columns(1), 0)
Range("C6") = .Sum(Sheets("Data").Range("B1").Offset(r1 - 1).Resize(r2 - r1))
Exit Sub
End If
If Range("C11") <> "" And Range("C12") <> "" Then
r1 = .Match(Range("C11"), Sheets("Data").Columns(1), 0) - 1
r2 = 1
Do Until .Sum(Sheets("Data").Range("B1").Offset(r1 - r2).Resize(r2)) >= Range("C12")
r2 = r2 + 1
Loop
Range("C14") = .Index(Sheets("Data").Columns(1), r1 - r2 + 1)
Exit Sub
End If
End With
MsgBox "Not enough info"
End Sub
teylyn: in the second method you start from L, not M. I see your solution will probably be two lines long...
Bookmarks