This function takes in row and column coordinates and a range, and uses those inputs to calculate and return a value via linear interpolation between the values in the range. It loops through the rows and columns of the range, calculating slope triangles between points. If the row matches a point, it calculates the value based on that point's slope. Otherwise, it calculates slopes on both sides of the diagonal and uses those to interpolate the value.
1 of 1
Download to read offline
More Related Content
Ns 2 chieu
1. Function TraBang2Chieu(ByVal Hang, ByVal Cot, VungChon As Range)
'PMXD'
Dim i As Long, j As Long
Dim TangAnPha
Dim NoiSuy1 As Double, NoiSuy2 As Double
For i = 1 To UBound(VungChon.Value, 2) ' Theo phuong ngang
If Hang = VungChon(1, i) Then
For j = 1 To UBound(VungChon.Value, 1) - 1
If (Cot - VungChon(j, 1)) * (Cot - VungChon(j + 1, 1)) <= 0 Then
TangAnPha = (VungChon(j + 1, i) - VungChon(j, i)) / (VungChon(j + 1,
1) - VungChon(j, 1))
TraBang2Chieu = VungChon(j, i) + (Cot - VungChon(j, 1)) * TangAnPha
GoTo Thoat:
End If
Next j
ElseIf (Hang - VungChon(1, i)) * (Hang - VungChon(1, i + 1)) < 0 Then
For j = 1 To UBound(VungChon.Value, 1) - 1
If (Cot - VungChon(j, 1)) * (Cot - VungChon(j + 1, 1)) < 0 Then
TangAnPha = (VungChon(j, i + 1) - VungChon(j, i)) / (VungChon(1, i +
1) - VungChon(1, i))
NoiSuy1 = VungChon(j, i) + (Hang - VungChon(1, i)) * TangAnPha
TangAnPha = (VungChon(j + 1, i + 1) - VungChon(j + 1, i)) /
(VungChon(1, i + 1) - VungChon(1, i))
NoiSuy2 = VungChon(j + 1, i) + (Hang - VungChon(1, i)) * TangAnPha
TangAnPha = (NoiSuy2 - NoiSuy1) / (VungChon(j + 1, 1) - VungChon(j,
1))
TraBang2Chieu = NoiSuy1 + (Cot - VungChon(j, 1)) * TangAnPha
GoTo Thoat:
End If
Next j
End If
Next i
Thoat:
'TraBang = UBound(VungChon.Value, 2)
End Function