option explicit
Public Function NoiSuy(x As Double, r As Range) As Double
Dim CompareCell As Range
Dim Comparecell1
For Each CompareCell In r.Rows(1).Cells
If (x < 1) Or (x > 11) Then
MsgBox "du lieu dau vao khong hop le", vbOKOnly
Exit Function
End If
If CompareCell.Value = x Then
NoiSuy = CompareCell.Offset(1, 0)
Exit Function
End If
Next CompareCell
For Each Comparecell1 In r.Rows(1).Cells
If (x > Comparecell1.Value) And (x < Comparecell1.Value + 2) Then
NoiSuy = Abs((x - Comparecell1.Value)) / 2 * Abs((Comparecell1.Offset(1, 1).Value - Comparecell1.Offset(1, 0).Value)) + Comparecell1.Offset(1, 0).Value
Exit Function
End If
Next Comparecell1
End Function
p/s:Vừa học được cách trình bày này ^^:
