BeforeSave event problem

A

azu_daioh

I have this code:
-------------
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Const rngWeek As String = "nrmWWeek"
Const rngTotal As String = "gTotal"
Const rngLast As String = "lastDay"

On Error GoTo stoppit
Application.EnableEvents = False

If Me.Range(rngLast).Value <> 0 Then
If Me.Range(rngTotal).Value <> Me.Range(rngWeek).Value Then
Response = MsgBox("The weekly total in cell G88 should
match the value in cell B1" _
, vbOKOnly, "Total Hours Error")
Cancel = True
End If
End If

stoppit:
Application.EnableEvents = True

End Sub
----------

What I want to accomplish is to display a message when the user clicks
on the "save" button when the numbers in 2 cells dont match. But for
some reason, the above code continues to save the workbook even the
values dont match. Please help.

Thank you,
Sharon
 
A

azu_daioh

Can i enter the BeforeSave even in the worksheet code? or does it has
to be in the ThisWorkbook?

If I can only use it in the "ThisWorkbook" -- how to I refer back to
the code in the worksheet?
 
A

azu_daioh

Nevermind. I figured it out. For some reason whenever I post the
problem, and read my own posts, sometimes I could come up with my own
solution. Weird.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

BeforeClose event help 3
Screen Flickers and slows down worksheet functions 5
cell change 8
BeforeSave 7
BeforeSave Problems 2
BeforeSave Event 5
Infinite loop cancelling BeforeSave 10
Automatically copy with save? 8

Top