我对 vba 宏比较陌生,并且已经学会了解决问题,但不是很擅长调试或解决问题。
我有这个正在退出的宏:
.Range("B" & y_lst).Resize(34, 10).Insert Shift:=xlDown
该宏适用于 2 个工作簿。'wscflow' 是全局声明的非活动打开工作簿 'wbsource' 上的工作表。Fluid_Results 是活动工作簿中的例程,是另一个模块。'wsactive' 是宏访问的工作表,并在调用 Read_Complex 的例程中设置。'Read_Pipe' 是这个模块中的一个例程。
谁能告诉我为什么这条线会导致宏退出?
我应该澄清一下;该行执行,但随后立即退出,它不执行下一行。
问候,亚瑟
Sub Read_Complex()
Dim x_lst As Integer, y_lst As Integer, z_lst As Integer, i As Integer
wscflow.Range("T7").Value = 10
Application.Run ("'" & wbsource.Name & "'!Set_Rng")
x_lst = wscflow.Range("S7").Value
z_lst = wsactive.Range("B" & Rows.Count).End(xlUp).Row - 23
z_lst = ((z_lst - 24) + 330) / 34
If wscflow.Range("O" & x_lst).Value = "Total:" Then
x_lst = x_lst - 2
End If
Call Fluid_Results
If x_lst = 10 Then
MsgBox ("Only one pipe," & vbCr & _
"please use Single Pipe Flow")
Else
For x = 10 To x_lst
y_lst = wsactive.Range("B" & Rows.Count).End(xlUp).Row - 22
wscflow.Range("T7").Value = x
Application.Run ("'" & wbsource.Name & "'!Set_Rng")
Application.Run ("'" & wbsource.Name & "'!Rev_Copy")
Application.Run ("'" & wbsource.Name & "'!Fwd_Copy")
With wsactive
If x < 12 Then
y_lst = y_lst - 1
Call Read_Pipe
If .Name = "Series_Pipe_Flow" Then
.Range("F" & y_lst).Offset(8, 0).Formula = "=F14+F48"
For i = 17 To 20
.Range("F" & y_lst).Offset(i, 0).Formula = "=F" & i + 7 & "+F" & i + 41
Next i
For i = 22 To 23
.Range("F" & y_lst).Offset(i, 0).Formula = "=F" & i + 11 & "+F" & i + 45
Next i
ElseIf .Name = "Parallel_Pipe_Flow" Then
.Range("F" & y_lst).Offset(15, 0).Formula = "=F22+F56"
.Range("F" & y_lst).Offset(19, 0).Formula = "=F27+F61"
.Range("F" & y_lst).Offset(22, 0).Formula = "=F33+F67"
.Range("F" & y_lst).Offset(23, 0).Formula = "=F34+F68"
End If
Else
If x_lst = z_lst Then
y_lst = y_lst - 1
Else
.Range("B35:K68").Copy
.Range("B" & y_lst).Resize(34, 10).Insert Shift:=xlDown
' .Range("B" & y_lst).PasteSpecial xlPasteAll
y_lst = y_lst + 33
Application.CutCopyMode = False
End If
Call Read_Pipe
If .Name = "Series_Pipe_Flow" Then
.Range("F" & y_lst).Offset(8, 0).Value = .Range("F" & y_lst).Offset(8, 0).Value _
+ .Range("F" & y_lst).Offset(-20, 0).Value
.Range("F" & y_lst).Offset(11, 0).Value = .Range("F" & y_lst).Offset(-17, 0).Value
.Range("F" & y_lst).Offset(14, 0).Value = .Range("F" & y_lst).Offset(-14, 0).Value
For i = 17 To 20
.Range("F" & y_lst).Offset(i, 0).Value = .Range("F" & y_lst).Offset(i, 0).Value _
+ .Range("F" & y_lst).Offset(i - 27, 0).Value
Next i
For i = 22 To 23
.Range("F" & y_lst).Offset(i, 0).Value = .Range("F" & y_lst).Offset(i, 0).Value _
+ .Range("F" & y_lst).Offset(i - 23, 0).Value
Next i
ElseIf .Name = "Parallel_Pipe_Flow" Then
.Range("F" & y_lst).Offset(15, 0).Value = .Range("F" & y_lst).Offset(15, 0).Value _
+ .Range("F" & y_lst).Offset(-12, 0).Value
.Range("F" & y_lst).Offset(19, 0).Value = .Range("F" & y_lst).Offset(19, 0).Value _
+ .Range("F" & y_lst).Offset(-7, 0).Value
.Range("F" & y_lst).Offset(22, 0).Value = .Range("F" & y_lst).Offset(22, 0).Value _
+ .Range("F" & y_lst).Offset(-1, 0).Value
.Range("F" & y_lst).Offset(23, 0).Value = .Range("F" & y_lst).Offset(23, 0).Value _
+ .Range("F" & y_lst).Offset(0, 0).Value
End If
End If
End With
Next x
End If
z_lst = wsactive.Range("B" & Rows.Count).End(xlUp).Row - 23
z_lst = ((z_lst - 24) + 330) / 34
For i = 0 To z_lst - x_lst + 1
wsactive.Range("B" & y_lst + 1).Offset(-i * 34, 0).PageBreak = xlPageBreakManual
Next i
wscflow.Range("T7").ClearContents
End Sub