Friday, 23 August 2013

Running a macro automatically in one sheet when workbook is opened

Running a macro automatically in one sheet when workbook is opened

I'm trying to run a macro automatically when a workbook is opened. I was
using the privatesub command in ThisWorkbook tab. However it seems when I
shut the Excel file and open it again, the macro has run on another sheet
as well resulting in a circular references error. How do I solve this so
it only runs on one sheet ("Cover Sheet"). Would placing the macro in he
actual sheet module work?
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

No comments:

Post a Comment