使用VBA的新手并不了解它。将其用于工程项目以解决深层边坡稳定性问题。当输入前7个计算时,VBA在用户表格中正确地解决了这些问题。但是当我尝试计算第8个公式(AVHS8)时它会给我一个错误,因为运行时错误“13”类型不匹配。我不确定问题是什么,公式完美地工作。如果有人能帮助它将非常感激。问题如下。
BES = 2.5 RAD = 18.58 DTCP = 7.5且OH = 17,这些只是设定且不变的数字
Private Sub Calculate_Click()
RAD = Sqr(DTCP ^ 2 + OH ^ 2)
BES = DTCP / 3
AVHS1 = (0)
AVHS2 = (Sqr(RAD ^ 2 - (DTCP - BES) ^ 2) - OH)
AVHS3 = (Sqr(RAD ^ 2 - (DTCP - BES - BES) ^ 2) - (OH) + (Tan(30 * 3.14 / 180) * BES))
AVHS4 = (Sqr(RAD ^ 2 - (DTCP - BES - BES - BES) ^ 2) - (OH) + (Tan(30 * 3.14 / 180) * BES * 2))
AVHS5 = (Sqr(RAD ^ 2 - (DTCP - BES - BES) ^ 2) - (OH) + (Tan(30 * 3.14 / 180) * BES * 3))
AVHS6 = (Sqr(RAD ^ 2 - (DTCP - BES) ^ 2) - (OH) + (Tan(30 * 3.14 / 180) * BES * 4))
AVHS7 = (Sqr(RAD ^ 2 - (DTCP) ^ 2) - (OH) + (Tan(30 * 3.14 / 180) * BES * 5))
'VBA can solve all the above code. it cant solve the code below (AVHS8)
AVHS8 = (Sqr(RAD ^ 2 - (DTCP + BES) ^ 2) - (OH) + (Tan(30 * 3.14 / 180) * BES * 6))
答案 0 :(得分:0)
我认为这些是你的表单上的控件而不是变量,这可以解释问题。作为控件,内容是文本,当您使用(DTCP + BES)
实际返回7.52.5
而不是10时,因为+
也可以作为连接运算符使用。将最后一行更改为:
AVHS8 = (Sqr(RAD ^ 2 - (CDbl(DTCP) + CDbl(BES)) ^ 2) - (OH) + (Tan(30 * 3.14 / 180) * BES * 6))
答案 1 :(得分:0)
Sub Leverage()
Dim i As Long
Dim counter_less As Long
Dim count_pos As Long
Dim row_count As Long
Dim num As Variant
num = InputBox("Enter threshold")
row_count = Cells(1, 1).CurrentRegion.Rows.Count - 2
counter_pos = 0
counter_less = 0
For i = 1 To row_count
If Abs(Cells(i + 2, 3)) > num And Cells(i + 3, 3) <> "" Then
counter_less = counter_less + 1
If Cells(i + 3, 3) < 0 And i Then
counter_pos = counter_pos + 1
End If
End If
Next
counter_pos = counter_pos / (counter_less)
counter_less = counter_less / row_count
MsgBox counter_pos & " %"`enter code here`
End Sub
I get error 6: Overflow. Anyone has any suggestions?