1
我試圖在打開工作簿時自動運行宏。我在ThisWorkbook標籤中使用了privatesub
命令。工作簿打開時在一張表中自動運行宏
但是,當我關閉Excel文件並再次打開它時,宏已經在另一張紙上運行,並導致循環引用錯誤。我如何解決這個問題,因此它只能在一張紙上運行(「封面」)。將宏放在他實際的工作表模塊工作?
Private Sub Workbook_Open()
With Sheets("Cover Sheet")
With Range("B21")
.Formula = "=COUNTIFS('Design Risk Scoring Sheet'!$AN$12:$AN$" & Sheets("Design Risk Scoring Sheet").Cells(Rows.count, "AN").End(xlUp).Row & ",""<""&B20, 'Design Risk Scoring Sheet'!$B$12:$B$" & Sheets("Design Risk Scoring Sheet").Cells(Rows.count, "AN").End(xlUp).Row & ", """")"
.AutoFill Destination:=Range("B21:AF21"), Type:=xlFillDefault
End With
With Range("B22")
.Formula = "=COUNTIFS('Design Risk Scoring Sheet'!$BF$12:$BF$" & Sheets("Design Risk Scoring Sheet").Cells(Rows.count, "AN").End(xlUp).Row & ",""<""&B20, 'Design Risk Scoring Sheet'!$B$12:$B$" & Sheets("Design Risk Scoring Sheet").Cells(Rows.count, "AN").End(xlUp).Row & ", """")"
.AutoFill Destination:=Range("B22:AF22"), Type:=xlFillDefault
End With
End With
謝謝我試一下,看看它是否工作。我已將它放在「封面」上,現在看起來可行。 – AAli