save on condition

G

Guye

hi all,

i need to creat an excel that prevent the user to save the file unless
he enters data on certain cells, for example
if the user enters data on cell E10 he must also enter data on cell
F10, if he doesnt do that he cant save the file and a msgbox appears
that ask him to enter the missing data.
 
N

Norman Jones

Hi Guye,

Try:

'=============>>
Private Sub Workbook_BeforeSave( _
ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
Dim SH As Worksheet

Set SH = Me.Sheets("Sheet2") '<<=== CHANGE

With SH
If Not IsEmpty(.Range("E10")) Then
If IsEmpty(Range("F10")) Then
Cancel = True
MsgBox ("Your message")
End If
End If
End With

End Sub
'<<=============

This is workbook event code and should be pasted into the workbook's
ThisWorkbook module *not* a standard module or a sheet module:

Right-click the Excel icon on the worksheet
(or the icon to the left of the File menu if your workbook is maximised)
Select 'View Code' from the menu and paste the code.
Alt-F11 to return to Excel.
 
P

papou

Hello
Place this code into Thisworkbook and amend accordingly:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
With Worksheets("Sheet1")
If .Range("E10").Value <> "" And .Range("F10").Value <> "" Then
Cancel = False
Else
Cancel = True
MsgBox "Please note input is required into both cells E10 and F10 on sheet
SHEET1"
End If
End With
End Sub

HTH
Cordially
Pascal
 
G

Guye

hi,
thanks for the solutions.
but i need the code to work on the 2 worksheet of the file.
and to check it not only on the cells mentioned, but on cells G10 as a
pair H10 and so forth, for all rows.
if you can help me it would bw wonderful,
and thanks,
Guy
 
G

Guye

hi,
to be more accurate, it must apply to the 26 first columns and 1000
rows on each work sheet.

thanks
 

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

Top