hungpronc9
Thành viên mới

- Tham gia
- 29/8/16
- Bài viết
- 8
- Được thích
- 0
Nội suy 1 chiều khi 1 chiều bằng 0.1 cố định chỉ thay đổi giá trị của cột. Nó bảo lỗi A value used in the formula as is the wrong of data type
0,1
10 0
12 0,04 Hàm đây =noisuy1($H$21:$I$29;11)
14 0,08
16 0,12
18 0,15
20 0,2
22 0,24
24 0,27
26 0,31
Function noisuy1(vungtra As Range, X As Double, cot As Integer) As Double
'ham noi suy 1 chieu
Dim ktra As Boolean
Dim i As Integer
Dim x1 As Double, x2 As Double, y1 As Double, y2 As Double
For i = 1 To vungtra.Cells.Count
If (vungtra.Cells(i, 1) <= X And vungtra.Cells(i + 1, 1) >= X) Or _
(vungtra.Cells(i + 1, 1) <= X And vungtra.Cells(i, 1) >= X) Then
x1 = vungtra.Cells(i, 1): x2 = vungtra.Cells(i + 1, 1)
y1 = vungtra.Cells(i, cot): y2 = vungtra.Cells(i + 1, cot)
noisuy1 = (y2 - y1) * (X - x1) / (x2 - x1) + y1
Exit Function
End If
Next i
MsgBox "gia tri can tim ko nam trong bang tra", vbInformation
End Function
Function noisuy2(vtra As Range, X As Double, Y As Double) As Double
'ham noi suy 2 chieu
Dim ktra As Boolean, vungtra
Dim i As Integer, j As Integer
Dim x1 As Double, x2 As Double, y1 As Double, y2 As Double
Dim a11 As Double, a12 As Double, a21 As Double, a22 As Double
Dim t1 As Double, t2 As Double
vungtra = vtra
For j = 2 To UBound(vungtra, 2) - 1
If (vungtra(1, j) <= Y And vungtra(1, j + 1) >= Y) Or _
(vungtra(1, j + 1) <= Y And vungtra(1, j) >= Y) Then
For i = 2 To UBound(vungtra, 1) - 1
If (vungtra(i, 1) <= X And vungtra(i + 1, 1) >= X) Or _
(vungtra(i, 1) <= X And vungtra(i + 1, 1) >= X) Then
x1 = vungtra(i, 1): x2 = vungtra(i + 1, 1)
y1 = vungtra(1, j): y2 = vungtra(1, j + 1)
a11 = vungtra(i, j): a12 = vungtra(i, j + 1)
a21 = vungtra(i + 1, j): a22 = vungtra(i + 1, j + 1)
t1 = (a12 - a11) * (Y - y1) / (y2 - y1) + a11
t2 = (a22 - a21) * (Y - y1) / (y2 - y1) + a21
noisuy2 = (t2 - t1) * (X - x1) / (x2 - x1) + t1
Exit Function
End If
Next i
End If
Next j
MsgBox "gia tri can tim ko nam trong bang tra", vbInformation
End Function
0,1
10 0
12 0,04 Hàm đây =noisuy1($H$21:$I$29;11)
14 0,08
16 0,12
18 0,15
20 0,2
22 0,24
24 0,27
26 0,31
Function noisuy1(vungtra As Range, X As Double, cot As Integer) As Double
'ham noi suy 1 chieu
Dim ktra As Boolean
Dim i As Integer
Dim x1 As Double, x2 As Double, y1 As Double, y2 As Double
For i = 1 To vungtra.Cells.Count
If (vungtra.Cells(i, 1) <= X And vungtra.Cells(i + 1, 1) >= X) Or _
(vungtra.Cells(i + 1, 1) <= X And vungtra.Cells(i, 1) >= X) Then
x1 = vungtra.Cells(i, 1): x2 = vungtra.Cells(i + 1, 1)
y1 = vungtra.Cells(i, cot): y2 = vungtra.Cells(i + 1, cot)
noisuy1 = (y2 - y1) * (X - x1) / (x2 - x1) + y1
Exit Function
End If
Next i
MsgBox "gia tri can tim ko nam trong bang tra", vbInformation
End Function
Function noisuy2(vtra As Range, X As Double, Y As Double) As Double
'ham noi suy 2 chieu
Dim ktra As Boolean, vungtra
Dim i As Integer, j As Integer
Dim x1 As Double, x2 As Double, y1 As Double, y2 As Double
Dim a11 As Double, a12 As Double, a21 As Double, a22 As Double
Dim t1 As Double, t2 As Double
vungtra = vtra
For j = 2 To UBound(vungtra, 2) - 1
If (vungtra(1, j) <= Y And vungtra(1, j + 1) >= Y) Or _
(vungtra(1, j + 1) <= Y And vungtra(1, j) >= Y) Then
For i = 2 To UBound(vungtra, 1) - 1
If (vungtra(i, 1) <= X And vungtra(i + 1, 1) >= X) Or _
(vungtra(i, 1) <= X And vungtra(i + 1, 1) >= X) Then
x1 = vungtra(i, 1): x2 = vungtra(i + 1, 1)
y1 = vungtra(1, j): y2 = vungtra(1, j + 1)
a11 = vungtra(i, j): a12 = vungtra(i, j + 1)
a21 = vungtra(i + 1, j): a22 = vungtra(i + 1, j + 1)
t1 = (a12 - a11) * (Y - y1) / (y2 - y1) + a11
t2 = (a22 - a21) * (Y - y1) / (y2 - y1) + a21
noisuy2 = (t2 - t1) * (X - x1) / (x2 - x1) + t1
Exit Function
End If
Next i
End If
Next j
MsgBox "gia tri can tim ko nam trong bang tra", vbInformation
End Function
Lần chỉnh sửa cuối: