Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 44
Default Check for Non Blank and Blank Cells Before Save


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
  #2   Report Post  
Posted to microsoft.public.excel.misc
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

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 44
Default Check for Non Blank and Blank Cells Before Save

Hi Jim,

Thanks for the codes. They works.

I wonder if I could check for mandatiory entry of multiple cells in E6, J8,
N8, Q6, Q7, Q8, and Cell R7 must be left blank before allowing the working
sheet to save.
I prefer to have the prompt message for the mandatory cells.


Here are my codes.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

'Mandatory fill in Cells before allow to save

Dim cell As Range
For Each cell In Sheets("Account Profile").Range("E6,J8,N8,Q6,Q7,Q8")
If IsEmpty(cell.Value) Then
MsgBox "You must fill in cell " & cell.Address & " of the Account
Profile Worksheet."
Application.Goto cell
Cancel = True
Exit For
End If
Next cell

End Sub


Many thanks.

Igbert

"Jim Thomlinson" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check for blank cells with formula Bob Flanagan[_2_] Excel Discussion (Misc queries) 3 January 7th 09 04:12 AM
Using Vlookup and IF statements to check for blank cells Koomba Excel Worksheet Functions 4 September 27th 08 03:54 PM
check a row ignore blank cells print only those with text Rollo Tomasi Excel Discussion (Misc queries) 4 May 18th 07 08:32 AM
check for two blank cells before populating a 3rd. slinger Excel Worksheet Functions 6 October 25th 06 08:14 PM
Save As .XML, not exporting blank cells roblo Excel Discussion (Misc queries) 2 January 4th 06 03:09 PM


All times are GMT +1. The time now is 10:24 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"