我正在使用 Excel 2016 32 位和 Excel 2019 32 位。在这两个 Excel 版本中,程序化分配停止 VBA 执行,而没有任何消息。
信任中心设置设置为启用所有宏并信任对 VBA 项目模型的访问。
计算有效并且是正确的。
我正在使用的代码如下。当 LL95 变量的值分配给单元格时,执行停止。此时 VBA 停止,没有任何消息。
' Compute 95%, 85% and 75% Confidence Intervals
Public Sub ConfidenceIntervals(topInputRow As Integer, bottomInputRow As Integer, outputRow As Integer)
Dim avg As Double
Dim sd As Double
Dim n As Double
Dim LL95 As Double
Dim UL95 As Double
Dim LL85 As Double
Dim UL85 As Double
Dim LL75 As Double
Dim UL75 As Double
Dim intervalRange As Range
Dim rangeString As String
n = CDbl(bottomInputRow - topInputRow)
rangeString = "C" & CStr(topInputRow) & ":C" & CStr(bottomInputRow)
Set intervalRange = Worksheets("Samples").Range(rangeString)
avg = WorksheetFunction.Average(intervalRange)
sd = WorksheetFunction.StDev_S(intervalRange)
' 95% Confidence Intervals
LL95 = Exp(avg - sd * 2.2622 / Sqr(n))
UL95 = Exp(avg + sd * 2.2622 / Sqr(n))
' 85% Confidence Intervals
LL85 = Exp(avg - sd * 1.5737 / Sqr(n))
UL85 = Exp(avg + sd * 1.5737 / Sqr(n))
' 75% Confidence Intervals
LL75 = Exp(avg - sd * 1.2297 / Sqr(n))
UL75 = Exp(avg + sd * 1.2297 / Sqr(n))
' Write the intervals to the output row.
Sheets("Samples").Select
Cells(outputRow, 7).Value = LL95
Cells(outputRow, 8).Value = UL95
Cells(outputRow, 9).Value = LL85
Cells(outputRow, 10).Value = UL85
Cells(outputRow, 11).Value = LL75
Cells(outputRow, 12).Value = UL75
End Sub
- 我尝试了以下代码来分配值。但是,这会产生相同的行为。VBA 炸弹在
Rng.Value = LL95
.
Dim Rng As Range
Set Rng = Sheets("Samples").Cells(outputRow, 7)
Rng.Value = LL95
Set Rng = Sheets("Samples").Cells(outputRow, 8)
Rng.Value = UL95
Set Rng = Sheets("Samples").Cells(outputRow, 9)
Rng.Value = LL85
Set Rng = Sheets("Samples").Cells(outputRow, 10)
Rng.Value = UL85
Set Rng = Sheets("Samples").Cells(outputRow, 11)
Rng.Value = LL75
Set Rng = Sheets("Samples").Cells(outputRow, 12)
Rng.Value = UL75
我还尝试过:
设置工具 | 选项 | 一般 | 打破所有错误。不显示其他信息或错误消息。
添加 On Error Goto:(以获取更多信息)。
我在看什么?