Error Message

  • Thread starter Thread starter Jane
  • Start date Start date
J

Jane

Does anyboye know if I can create an error or reminder
message to appear when a user goes to close a file?
 
You could put some code in the Workbook_beforeclose event.

Option Explicit
Private Sub Workbook_BeforeClose(Cancel As Boolean)

Dim myRngToCheck As Range
Dim myKeyRange As Range

Set myRngToCheck = Me.Worksheets("sheet2").Range("a2,b9,c12")
Set myKeyRange = Me.Worksheets("sheet1").Range("a1")

If LCase(myKeyRange) = "x" Then
'it's you setting the master
myKeyRange.ClearContents
Else
With myRngToCheck
If .Cells.Count <> Application.CountA(.Cells) Then
MsgBox "Please finish data entry"
Cancel = True 'don't let them close???
End If
End With
End If

End Sub

As an example, I wanted the users to fill something in sheet2's a2, b9 and c12.
But you could just put a msgbox in there with your reminder, too.

But if you're setting this up, you'll want to be able to save with empty cells.
One way around this is to just a top secret indicator cell with a special key
value in it. (I chose sheet1 A1 with X.)


If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Short course:
activate your workbook
rightclick on the excel icon to the left of File menu option
(if the window is full sized)

or rightclick on the excel icon on the active window
(if the window isn't full screen)

Select view code
paste that in the right hand code window.

Save your workbook.

try leaving cells blank and then try it with the X.
 
Back
Top