View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Jim Thomlinson Jim Thomlinson is offline
external usenet poster
 
Posts: 5,939
Default Check for Non Blank and Blank Cells Before Save

Right click the XL icon in the top left hand corner of the XL screen and
select View code. That will take you into the ThisWorkbook code module within
the VBE. paste the following...


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
With Sheets("Sheet1")
If Not (.Range("A1").Value < "" And .Range("B1").Value = "") Then
MsgBox "Can't save file"
Cancel = True
End If
End With
End Sub

Note that when you do things like this you tend to frustrate your users.
They just want to save the file. Thye don't know what is supposed to be in A1
so they just put in anything to make it work. Or they 'need' to have
something in B1 and... or they are sure they saved the file but now it is not
there (because they did not read the warning that the file was not being
saved)... or...
--
HTH...

Jim Thomlinson


"igbert" wrote:


Does anyone know the VBA to only allow A1 is a non blank cell and B1 is a
blank cell before allowing the save?

Thanks


Igbert