Function find_date(ddate As Range, sum_range As Range, sum_range_over As Range, over_type_choose As Integer, target_no As Integer, base_date As Date)
tmp_sum = 0
tmp_date = 1
Dim dateArray, sumArray As Variant
dateArray = ddate.Value
If over_type_choose = 1 Then
sumArray = sum_range.Value
Else
sumArray = sum_range_over.Value
End If
For i = 1 To UBound(dateArray)
If dateArray(i, 1) >= base_date Then
tmp_sum = tmp_sum + sumArray(i, 1)
End If
If tmp_sum > target_no Then
tmp_date = dateArray(i, 1)
Exit For
End If
Next
find_date = tmp_date
End Function