Option Explicit
Function TraLuuLuong(LuuLuong As Range, VungTra As Range)
Dim R As Long, C As Long, BangTra, Nguyen As Double, Le As Double
BangTra = VungTra
[COLOR=#ff0000]If UBound(BangTra) = 16 Then[/COLOR]
[COLOR=#ff0000] Nguyen = WorksheetFunction.RoundDown(LuuLuong, 1)[/COLOR]
[COLOR=#ff0000]Else[/COLOR]
[COLOR=#ff0000] Nguyen = WorksheetFunction.RoundDown(LuuLuong, 0)[/COLOR]
[COLOR=#ff0000]End If[/COLOR]
Le = Round(LuuLuong - Nguyen, 6)
For R = 2 To UBound(BangTra, 1)
If BangTra(R, 1) = Nguyen Then
For C = 2 To UBound(BangTra, 2)
[COLOR=#ff0000] If BangTra(1, C) = Le Then[/COLOR]
[COLOR=#ff0000] TraLuuLuong = BangTra(R, C)[/COLOR]
[COLOR=#ff0000] Exit Function[/COLOR]
[COLOR=#ff0000] End If[/COLOR]
If BangTra(1, C) > Le Then Exit For
Next
C = C - 1
If C < UBound(BangTra, 2) Then
TraLuuLuong = BangTra(R, C) + (Le - BangTra(1, C)) * (BangTra(R, C + 1) - BangTra(R, C)) / (BangTra(1, C + 1) - BangTra(1, C))
Else
If R < UBound(BangTra, 1) Then
TraLuuLuong = BangTra(R, C) + (Le - BangTra(1, C)) * (BangTra(R + 1, 2) - BangTra(R, C)) / [COLOR=#ff0000](0.01)[/COLOR]
Else
TraLuuLuong = CVErr(xlErrNA)
End If
End If
Exit Function
End If
Next
End Function