我写这段代码但烧毁了两者之间的附加填料。根据选定的时间点,它将隐藏适当的行。VBA代码 - 跳过一些地方,如果一些别人excecuted
容器1每时每刻都会有,但是,如果没有选择另一个容器中,我希望它可以隐藏所有剩余的行而不处理代码的其余部分。因此,如果选择容器1和2,它将运行这些代码而不运行代码的其余部分。
,因为有这么多的可能的时间点,改写本作为循环将是极其复杂的,它更跳过不相关的代码的问题。几乎像goto线或什么的?我不知道!
是否有任何其他的方式,使这个代码的运行效率比暂时禁用DisplayPageBreaks,ScreenUpdating和启用活动?没有计算在页面上执行,只有行隐藏。
例如,如果Q26是空白的(无容器2)我希望它去的代码末尾,没有处理任何东西,但我怎么写它,它仍然处理代码的其余部分。
感谢您的帮助
If Worksheets("StabDataCapture").Range("q26").Value = "" Then Worksheets("Template").Rows("142:1048576").EntireRow.Hidden = True Else
谢谢您的帮助!
Sub Containers()
Dim xPctComp As Integer
Application.StatusBar = "Container 1: " & _
Format(xPctComp, "##0%")
ActiveSheet.DisplayPageBreaks = False
Application.EnableEvents = False
Application.ScreenUpdating = False
'CONTAINER 1 ROW HIDES
'@@@@@@@@@@@@@@@@@@@@@@@@@@@ 60°C @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'Show/Hide [email protected]
If Worksheets("StabDataCapture").Range("B33").Value = "" Then
Worksheets("Template").Rows("8:8").EntireRow.Hidden = True
End If
Application.StatusBar = "Container 2: " & _
Format(xPctComp, "##25%")
If Worksheets("StabDataCapture").Range("q26").Value = "" Then Worksheets("Template").Rows("142:1048576").EntireRow.Hidden = True Else
'CONTAINER 2 ROW HIDES
'@@@@@@@@@@@@@@@@@@@@@@@@@@@ 60°C @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'Show/Hide [email protected]
If Worksheets("StabDataCapture").Range("P33").Value = "" Then
Worksheets("Template").Rows("146:146").EntireRow.Hidden = True
End If
Application.StatusBar = "Container 3: " & _
Format(xPctComp, "##50%")
'CONTAINER 3 ROW HIDES
If Worksheets("StabDataCapture").Range("c91").Value = "" Then Worksheets("Template").Rows("280:1048576").EntireRow.Hidden = True Else
'@@@@@@@@@@@@@@@@@@@@@@@@@@@ 60°C @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'Show/Hide [email protected]
If Worksheets("StabDataCapture").Range("B98").Value = "" Then
Worksheets("Template").Rows("284:284").EntireRow.Hidden = True
End If
Application.StatusBar = "Container 4: " & _
Format(xPctComp, "##75%")
If Worksheets("StabDataCapture").Range("q91").Value = "" Then Worksheets("Template").Rows("418:1048576").EntireRow.Hidden = True Else
'@@@@@@@@@@@@@@@@@@@@@@@@@@@ 60°C @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'Show/Hide [email protected]
If Worksheets("StabDataCapture").Range("P98").Value = "" Then
Worksheets("Template").Rows("422:422").EntireRow.Hidden = True
End If
Application.EnableEvents = True
Application.ScreenUpdating = True
Application.StatusBar = ""
End Sub
你可以尝试使用'GoTo',但这不是很推荐......或者只是用更多的逻辑重新排列你的代码!不需要循环,但使用'If's或'Select's和正确的缩进,你可以这样做 – R3uK
使用局部变量,例如w =工作表(“StabDataCapture”)并稍后引用它们(或With块)可能会提供一个非常小的改进(只有在为每个选定单元格的更改调用此函数时才会计数)。我也会尝试Application.Calculation = xlManual,即使你认为没有太多的计算。但是,我没有看到为什么你的代码应该很慢。正如R3uK也指出的那样,这种缩进是可怕的。 – z32a7ul
如果您也从另一个调用此函数,则保存DisplayPageBreaks,EnableEvents等的值,并在最后将其恢复到原始值。否则,这个子的调用者可能会放弃这些优化,如果它也使用它们的话。 – z32a7ul