我有一个VBA代码,其中包含针对不同单元格的多个公式,包括数组公式。该代码有效,但是运行非常缓慢。关于如何加快速度的任何提示?
Sub AssetbyStatus()
Application.Calculation = xlManual
With ActiveWorkbook.Names("Cat")
.Name = "Cat"
.RefersToR1C1 = "=Dashboard!R2C9:R100000C9"
With ActiveWorkbook.Names("Linetag")
.Name = "Linetag"
.RefersToR1C1 = "=Dashboard!R2C3:R100000C3"
With ActiveWorkbook.Names("Incl")
.Name = "Incl"
.RefersToR1C1 = "=Dashboard!R2C4:R100000C4"
With ActiveWorkbook.Names("MasterID")
.Name = "MasterID"
.RefersToR1C1 = "=Dashboard!R2C1:R100000C1"
With ActiveWorkbook.Names("Cattype")
.Name = "Cattype"
.RefersToR1C1 = "=Dashboard!R2C10:R100000C10"
End With
End With
End With
End With
End With
Range("R59").FormulaR1C1 = _
"=COUNTIFS(Dashboard!C1, ""<>*Master*"", Dashboard!C10, ""Neuro"")"
Range("R60").FormulaR1C1 = _
"=COUNTIFS(Dashboard!C1, ""<>*Master*"", Dashboard!C4, ""N"", Dashboard!C10, ""Neuro"")"
Range("R61").FormulaR1C1 = _
"=COUNTIFS(Dashboard!C1, ""<>*Master*"", Dashboard!C10, ""Neuro"", Dashboard!C9, ""Ceased"")"
Range("R62").FormulaR1C1 = _
"=COUNTIFS(Dashboard!C1, ""<>*Master*"", Dashboard!C10, ""Neuro"", Dashboard!C9, ""Follow-Up"")"
Range("R63").FormulaR1C1 = _
"=COUNTIFS(Dashboard!C1, ""<>*Master*"", Dashboard!C10, ""Neuro"", Dashboard!C9, ""A&A"")"
Range("R64").FormulaR1C1 = _
"=COUNTIFS(Dashboard!C1, ""<>*Master*"", Dashboard!C10, ""Neuro"", Dashboard!C9, ""Soft A&A"")"
Range("R65").FormulaR1C1 = _
"=COUNTIFS(Dashboard!C1, ""<>*Master*"", Dashboard!C10, ""Neuro"", Dashboard!C9, ""Monday"")"
Range("R66").FormulaR1C1 = _
"=COUNTIFS(Dashboard!C1, ""<>*Master*"", Dashboard!C10, ""Neuro"", Dashboard!C9, ""Meeting"")"
Range("R67").FormulaR1C1 = _
"=COUNTIFS(Dashboard!C1, ""<>*Master*"", Dashboard!C10, ""Neuro"", Dashboard!C9, ""CDA"")"
Range("R68").FormulaR1C1 = _
"=COUNTIFS(Dashboard!C1, ""<>*Master*"", Dashboard!C10, ""Neuro"", Dashboard!C9, ""BB"")"
Range("R69").FormulaR1C1 = _
"=COUNTIFS(Dashboard!C1, ""<>*Master*"", Dashboard!C10, ""Neuro"", Dashboard!C9, ""TS"")"
Range("R70").FormulaR1C1 = "=R[-11]C-SUM(R[-10]C:R[-1]C)"
Range("S59").FormulaArray = _
"=SUM(IF(FREQUENCY(IF(--(ISNUMBER(SEARCH(""Master"",MasterID)))=0,IF(Cattype=""Neuro"",MATCH(Linetag,Linetag,0))),ROW(Linetag)-ROW(Dashboard!R2C3)+1),1))"
Range("S60").FormulaArray = _
"=SUM(IF(FREQUENCY(IF(--(ISNUMBER(SEARCH(""Master"",MasterID)))=0,IF(Incl=""N"",IF(Cattype=""Neuro"",MATCH(Linetag,Linetag,0)))),ROW(Linetag)-ROW(Dashboard!R2C3)+1),1))"
Range("S61").FormulaArray = _
"=SUM(IF(FREQUENCY(IF(--(ISNUMBER(SEARCH(""Master"",MasterID)))=0, IF(--(ISNUMBER(SEARCH(""Cease"",Cat)))=1,IF(Cattype=""Neuro"",MATCH(Linetag,Linetag,0)))),ROW(Linetag)-ROW(Dashboard!R2C3)+1),1))"
Range("S62").FormulaArray = _
"=SUM(IF(FREQUENCY(IF(--(ISNUMBER(SEARCH(""Master"",MasterID)))=0, IF(--(ISNUMBER(SEARCH(""Follow"",Cat)))=1,IF(Cattype=""Neuro"",MATCH(Linetag,Linetag,0)))),ROW(Linetag)-ROW(Dashboard!R2C3)+1),1))"
Range("S63").FormulaArray = _
"=SUM(IF(FREQUENCY(IF(--(ISNUMBER(SEARCH(""Master"",MasterID)))=0,IF(Cat=""A&A"",IF(Cattype=""Neuro"",MATCH(Linetag,Linetag,0)))),ROW(Linetag)-ROW(Dashboard!R2C3)+1),1))"
Range("S64").FormulaArray = _
"=SUM(IF(FREQUENCY(IF(--(ISNUMBER(SEARCH(""Master"",MasterID)))=0,IF(Cat=""Soft A&A"",IF(Cattype=""Neuro"",MATCH(Linetag,Linetag,0)))),ROW(Linetag)-ROW(Dashboard!R2C3)+1),1))"
Range("S65").FormulaArray = _
"=SUM(IF(FREQUENCY(IF(--(ISNUMBER(SEARCH(""Master"",MasterID)))=0,IF(Cat=""Monday"",IF(Cattype=""Neuro"",MATCH(Linetag,Linetag,0)))),ROW(Linetag)-ROW(Dashboard!R2C3)+1),1))"
Range("S66").FormulaArray = _
"=SUM(IF(FREQUENCY(IF(--(ISNUMBER(SEARCH(""Master"",MasterID)))=0,IF(Cat=""Meeting"",IF(Cattype=""Neuro"",MATCH(Linetag,Linetag,0)))),ROW(Linetag)-ROW(Dashboard!R2C3)+1),1))"
Range("S67").FormulaArray = _
"=SUM(IF(FREQUENCY(IF(--(ISNUMBER(SEARCH(""Master"",MasterID)))=0,IF(Cat=""CDA"",IF(Cattype=""Neuro"",MATCH(Linetag,Linetag,0)))),ROW(Linetag)-ROW(Dashboard!R2C3)+1),1))"
Range("S68").FormulaArray = _
"=SUM(IF(FREQUENCY(IF(--(ISNUMBER(SEARCH(""Master"",MasterID)))=0,IF(Cat=""BB"",IF(Cattype=""Neuro"",MATCH(Linetag,Linetag,0)))),ROW(Linetag)-ROW(Dashboard!R2C3)+1),1))"
Range("S69").FormulaArray = _
"=SUM(IF(FREQUENCY(IF(--(ISNUMBER(SEARCH(""Master"",MasterID)))=0,IF(Cat=""TS"",IF(Cattype=""Neuro"",MATCH(Linetag,Linetag,0)))),ROW(Linetag)-ROW(Dashboard!R2C3)+1),1))"
Range("S70").FormulaR1C1 = "=R[-11]C-SUM(R[-10]C:R[-1]C)"
Range("P75").FormulaArray = _
"=IFERROR(INDEX(MasterID,SMALL(IF(ISERROR(SEARCH(R72C16,MasterID))*
ISNUMBER(SEARCH(R73C16,Cat))*ISNUMBER(SEARCH(R57C16,Cattype))*
(COUNTIF(R74C16:R[-1]C16,MasterID)=0),ROW(MasterID)-
ROW(Dashboard!R2C1)+1),1)),"""")"
Range("Q75").FormulaR1C1 = _
"=IFERROR(VLOOKUP(RC[-1], Dashboard!C1:C12, 12, FALSE),"""")"
Range("P75:Q75").Select
Selection.AutoFill Destination:=Range("P75:Q91"), Type:=xlFillDefault
Range("R75").FormulaArray = _
"=IFERROR(INDEX(MasterID,SMALL(IF(ISERROR(SEARCH(R72C16,MasterID))
*ISNUMBER(SEARCH(R73C16,Cat))*ISNUMBER(SEARCH(R57C16,Cattype))*
(COUNTIF(R74C18:R[-1]C18,MasterID)=0),ROW(MasterID)-
ROW(Dashboard!R2C1)+1),1)),"""")"
Range("S75").FormulaR1C1 = _
"=IFERROR(VLOOKUP(RC[-1], Dashboard!C1:C12, 12, FALSE),"""")"
Range("R75:S75").Select
Selection.AutoFill Destination:=Range("R75:S91"), Type:=xlFillDefault
Application.Calculation = xlAutomatic
End Sub
我尝试添加以下项目: Application.ScreenUpdating = False Application.DisplayStatusBar = False
以及使用“手动”和“自动”编码,但没有找到任何方法可以加快速度。