Do not allow a file to be saved if "ERROR" is in any field
I'm using IF conditions to check certain cells for negative numbers - if
they're negative the output is "ERROR". I wanted to know if there is a way to prevent the file from being saved if "ERROR" is in any cell in the workbook. |
Do not allow a file to be saved if "ERROR" is in any field
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean) Dim sh As Worksheet For Each sh In ThisWorkbook.Worksheets If sh.Evaluate("SUMPRODUCT(--(ISERROR(" & _ ActiveSheet.UsedRange.Address & ")))") 0 Then MsgBox "Errors in file" Cancel = True Exit For End If Next sh End Sub 'This is workbook event code. 'To input this code, right click on the Excel icon on the worksheet '(or next to the File menu if you maximise your workbooks), 'select View Code from the menu, and paste the code -- HTH RP (remove nothere from the email address if mailing direct) "pmms" wrote in message ... I'm using IF conditions to check certain cells for negative numbers - if they're negative the output is "ERROR". I wanted to know if there is a way to prevent the file from being saved if "ERROR" is in any cell in the workbook. |
All times are GMT +1. The time now is 05:17 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com