Function NS3YT(VungTra As Range, xeduong As Range, _
taitrong As String, Duong As String, luuluong As Double) As Double
Dim i As Integer
Dim x1 As Double, x2 As Double, y1 As Double, y2 As Double
Dim hang As Integer
For i = 1 To xeduong.Cells.Count
If Application.WorksheetFunction.Match(taitrong & Duong, xeduong, 0) = i Then
hang = i + 1
End If
Next i
For i = 1 To VungTra.Cells.Count
If VungTra.Cells(1, i) <= luuluong And VungTra.Cells(1, i + 1) >= luuluong Then
x1 = VungTra.Cells(1, i): x2 = VungTra.Cells(1, i + 1)
y1 = VungTra.Cells(hang, i): y2 = VungTra.Cells(hang, i + 1)
NS3YT = y1 + (y2 - y1) * (luuluong - x1) / (x2 - x1)
End If
Next i
End Function