=INDEX($B$3:$B$8,MATCH(C11-1,$A$3:$A$8),1)
=VLOOKUP(C11-(C11<>$A$3),$A$3:$B$8,2,(C11<>$A$3))
[LEFT]=VLOOKUP(D11-(D11<>$A$3),$A$3:$C$8,3,(D11<>$A$3))[/LEFT]
Option Explicit
Function DoiChieu(Rng As Range, Ngay, Ten)
Dim lHg As Long, jZ As Long, iW As Long
Dim iCot As Integer
lHg = Rng.Rows.Count: iCot = Rng.Columns.Count
If iCot < 3 Or lHg < 2 Then
DoiChieu = ""
Else
For jZ = 1 To lHg
If Rng.Cells(jZ, 1) = Ngay Then Exit For
Next jZ
If jZ > lHg Then
DoiChieu = ""
Else
For iW = jZ - 1 To 1 Step -1
If Rng.Cells(iW, 2).Value = Ten Then Exit For
Next iW
If iW > 0 then DoiChieu = Rng.Cells(iW, 3)
End If
End If
End Function
anhtuan1066 đã viết:Bắp ơi! Thử cho 1 giãi pháp bằng VBA tham khảo với....
Function GT(Ngay As Range, Ten As Range, _
MangNgay As Range, MangTen As Range, MangGT As Range) As Long
Application.Volatile (False)
If MangNgay.Columns.Count > 1 Then Exit Function
If MangTen.Columns.Count > 1 Then Exit Function
If MangGT.Columns.Count > 1 Then Exit Function
If MangNgay.Rows.Count <> MangGT.Rows.Count Or _
MangTen.Rows.Count <> MangGT.Rows.Count Then Exit Function
Dim i As Integer, m As Integer
Dim NgayTemp As Date, TempGT As Long
For i = 1 To MangTen.Rows.Count
If UCase(MangTen(i)) = UCase(Ten) Then
If MangNgay(i) = Ngay.Value Then
GT = MangGT(i)
Exit Function
ElseIf MangNgay(i) < Ngay.Value Then
If MangNgay(i) >= NgayTemp Then
GT = MangGT(i)
NgayTemp = MangNgay(i)
End If
End If
End If
Next
End Function