简体   繁体   中英

VBA to Hide and Unhide Rows using an activex check box

Can someone help me make this more efficient? It is running around 10 seconds. Thanks much!

I've adapted this code to hide rows that contain "Hide" as the result of a formula in column A of my worksheet.

Sub Hide_Rows()

 Application.Calculation = xlCalculationAutomatic
 Application.ScreenUpdating = False
 With ActiveSheet
For Each cell In .Range("a7:a115")
 If cell.Value = "Hide" Then
 cell.EntireRow.Hidden = True
 End If
 Next
 End With
 Application.ScreenUpdating = True
 End Sub

I have a similar Show_Rows sub that unhides the hidden rows. I have linked the button result (True or False) to cell A1 and then I'm using an If statement to either Hide_Rows or Show_Rows in the check box VBA

Private Sub CheckBox1_Click()
If Cells(1, 1).Value = True Then
     Hide_Rows
 Else
    Show_Rows
End If
End Sub

Your problem may be with lots of complicated formulas like David Zemens says. You have the right idea with the Application.Calculation but it should be Application.Calculation = xlCalculationManual at the start, and then Application.Calculation = xlCalculationAutomatic at the end.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM