Hi all,
I have a macro built in to one of my worksheets (under view code).
This prompts a user to select either “Ok” or “Cancel” from a message box.
Private Sub Worksheet_Change(ByVal Target As Range)
Set t = Target
Set b = Range("B:B")
If Intersect(t, b) Is Nothing Then Exit Sub
Application.EnableEvents = False
x = MsgBox("RESET CALCULATIONS??'", vbOKCancel, "Reset?")
If x = vbCancel Then Exit Sub
ActiveSheet.Unprotect
ActiveCell.Offset(-1, 11).Select
Selection.FormulaR1C1 = _
"=IF(AVERAGE(Table!R3C4:R20C4)>5,IF(AVERAGE(Table!R3C4:R20C4)<31,IF(INDIRECT(""b""&ROW())=0,"""",IF(INDIRECT(""q""&ROW())=""X"",IF(INDIRECT(""y""&ROW())=1,INDIRECT(""u""&ROW()),""""),"""")),""""),"""")"
ActiveSheet.Protect DrawingObjects:=True, contents:=True, Scenarios:=True, AllowFiltering:=True,
End Sub
I also have a macro that is designed to run upon save or closure of the workbook which is built in to “this workbook”.
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
ThisWorkbook.Activate
ThisWorkbook.Sheets("Main").Select
Range("A5:O310").Select
Selection.Sort Key1:=Range("B5"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Range("B5").Select
End Sub
No for some reason, if “cancel” is selected from the first macro – it prevents the second macro from running on closure. If “ok” (or the first macro is not run) the second one will run perfectly.
Can anyone help please??
Bookmarks