所以我有下面的VBA宏設置,當CompHide運行時需要幾分鐘時間來更新。我覺得這是由於C.EntireRow.Columns(43).Value =「」加速VBA執行
這一行我試圖做一個新的「幫手」列,檢查是否兩列都是空的,並有它返回「Y」或「N」,然後讓宏查看「Y」並隱藏它們。這加快了速度,但我希望如果可以的話速度更快。
原單碼:
Sub CompHide()
Dim sht As Worksheet, C As Range
Application.ScreenUpdating = False
Application.EnableEvents = False
Set sht = Sheets("Comparison")
sht.Rows.Hidden = False
CSetRowVis "C9", "CMarket1"
CSetRowVis "C115", "CMarket2"
CSetRowVis "C221", "CMarket3"
CSetRowVis "C329", "CMarket4"
CSetRowVis "C437", "CMarket5"
CSetRowVis "C545", "CMarket6"
CSetRowVis "C653", "CMarket7"
CSetRowVis "C761", "CMarket8"
CSetRowVis "C869", "CMarket9"
CSetRowVis "C977", "CMarket10"
For Each C In sht.Range("CNonTest")
If C.Value = "" And C.EntireRow.Columns(43).Value = "" Then
C.EntireRow.Hidden = True
End If
Next
sht.Range("CBlank").EntireRow.Hidden = True
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
Sub CSetRowVis(addr As String, rngName As String)
With Sheets("Comparison")
If .Range(addr).Value = "Unused" Then
.Range(rngName).EntireRow.Hidden = True
End If
End With
End Sub
新代碼:
Sub CompHide()
Dim sht As Worksheet, C As Range
Application.ScreenUpdating = False
Application.EnableEvents = False
Set sht = Sheets("Comparison")
sht.Rows.Hidden = False
CSetRowVis "C9", "CMarket1"
CSetRowVis "C115", "CMarket2"
CSetRowVis "C221", "CMarket3"
CSetRowVis "C329", "CMarket4"
CSetRowVis "C437", "CMarket5"
CSetRowVis "C545", "CMarket6"
CSetRowVis "C653", "CMarket7"
CSetRowVis "C761", "CMarket8"
CSetRowVis "C869", "CMarket9"
CSetRowVis "C977", "CMarket10"
For Each C In sht.Range("CHideTest")
If C.Value = "Y" Then
C.EntireRow.Hidden = True
End If
Next
sht.Range("CBlank").EntireRow.Hidden = True
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
Sub CSetRowVis(addr As String, rngName As String)
With Sheets("Comparison")
If .Range(addr).Value = "Unused" Then
.Range(rngName).EntireRow.Hidden = True
End If
End With
End Sub
這是使用Excel 2013標準64位。行數剛剛低於1200.列數爲150.所有這些單元都是公式
如果有任何額外的信息,您需要讓我知道。
我投票作爲題外話,因爲它屬於在代碼審查 –
代碼評審關閉這個問題是一個事?我不知道這個。你能指出我的網址先生 –
http://codereview.stackexchange.com/ :) –