SkywardPalm
Board Regular
- Joined
- Oct 23, 2021
- Messages
- 61
- Office Version
- 365
- Platform
- Windows
I am trying to have this macro run before every save, to ensure that the two totals in question are matching. It only runs the first time I press ctrl+s
ThisWorkbook:
DollarTotalCheck:
ThisWorkbook:
VBA Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Call ExtendedTotalCheck
End Sub
VBA Code:
Sub ExtendedTotalCheck()
Application.EnableEvents = True
Dim wsMaster As Worksheet, wsSUMMARY As Worksheet
Dim extHeaderCell As Range, f As Range
Dim masterTotal As Double
Set wsMaster = ThisWorkbook.Sheets("Master")
Set wsSUMMARY = ThisWorkbook.Sheets("SUMMARY")
Set extHeaderCell = wsMaster.Range("1:1").Find("Extended")
If Not extHeaderCell Is Nothing Then
masterTotal = extHeaderCell.Offset(, 1).Value
Set f = wsSUMMARY.Range("C228:D228").Find(masterTotal, , xlValues, xlWhole)
If Not f Is Nothing Then
Debug.Print "Extended Totals Match"
Else
MsgBox "Please check Extended Totals match!"
End If
End If
End Sub