cell verification

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a sheet that when users input data in column N they need to put a
reason in column O. How can I ensure that the reason in entered in column O
before they save and close?
 
Right-click the excel LOGO near the File menu, select View code, paste this
in:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Application.CountA(Sheets("Sheet1").Range("N:N")) <>
Application.CountA(Sheets("Sheet1").Range("O:O")) Then
Cancel = True
MsgBox "Before this file can be saved, each item in column N must
have a reason in column O.", vbExclamation
End If
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
If Application.CountA(Sheets("Sheet1").Range("N:N")) <>
Application.CountA(Sheets("Sheet1").Range("O:O")) Then
Cancel = True
MsgBox "Before this file can be saved, each item in column N must
have a reason in column O.", vbExclamation
End If
End Sub

Bob Umlas
Excel MVP
 
Make the first Msgbox I suggested say "...can be closed..." instead of
"...can be saved..."
Bob Umlas
Excel MVP
 
Back
Top