Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Junior Member
 
Posts: 7
Default No save function if

Hello all.

I'm looking to write something that will not allow the user to save the sheet if things are not completed correctly. At the moment I have this but it doesnt seem to work.

in G9 on sheet 1

=IF(ISBLANK(B9),"",IF(OR(ISBLANK(B9),ISBLANK(C9),I SBLANK(D9),ISBLANK(E9),ISBLANK(F9)),"Not Complete","Complete"))

Which works fine. The issue is this......

[vba]Private Sub Workbook_BeforeSave(Cancel As Boolean)

If Sheet1.Range("G9").Value = "Not Complete" Then
MsgBox "Cannot save until ALL cells have been completed!"
Cancel = True
End If
End Sub[/vba]

Any advice is greatly recieved.

Many thanks

Jeff
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,872
Default No save function if

Hi Jeff,

Am Mon, 8 Dec 2014 11:29:40 +0000 schrieb Jeff Owen:

=IF(ISBLANK(B9),"",IF(OR(ISBLANK(B9),ISBLANK(C9),I SBLANK(D9),ISBLANK(E9),ISBLANK(F9)),"Not
Complete","Complete"))


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

With Sheets("Sheet1")
If WorksheetFunction.CountA(.Range("B9:F9")) < 5 Then
MsgBox "Cannot save until ALL cells have been completed!"
Cancel = True
End If
End With
End Sub


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
  #3   Report Post  
Junior Member
 
Posts: 7
Default

Hi Claus

Thanks for the reply - Issue is now I am unable to save the blank template as there is nothing in the cells.
Is there a way of putting greater than 1 but less than 5 in the formula?

Last edited by Jeff Owen : December 8th 14 at 01:04 PM
  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,872
Default No save function if

Hi Owen,

Am Mon, 8 Dec 2014 12:59:25 +0000 schrieb Jeff Owen:

Issue is now I am unable to save the blank
template as there is nothing in the cells.
Is there a way of putting greater than 1 but less than 5 in the formula?


try:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim LCol As Long

With Sheets("Sheet1")
'Search for the last used column in row 5
LCol = .Cells(5, Columns.Count).End(xlToLeft).Column
'If the cell in row9 in the last used column is empty
'Saving is cancelled
If Len(.Cells(9, LCol)) = 0 And LCol 1 Then
MsgBox "Cannot save until ALL cells have been completed!"
Cancel = True
End If
End With
End Sub


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
  #5   Report Post  
Junior Member
 
Posts: 7
Default

Quote:
try:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim LCol As Long

With Sheets("Sheet1")
'Search for the last used column in row 5
LCol = .Cells(5, Columns.Count).End(xlToLeft).Column
'If the cell in row9 in the last used column is empty
'Saving is cancelled
If Len(.Cells(9, LCol)) = 0 And LCol 1 Then
MsgBox "Cannot save until ALL cells have been completed!"
Cancel = True
End If
End With
End Sub
Unfortunatley not. Ihave tweaked your earlier formula though.


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

With Sheets("Sheet1")
If WorksheetFunction.CountA(.Range("B9:F9")) < 5 And WorksheetFunction.CountA(.Range("B9:F9")) 1 Then
MsgBox "Cannot save until ALL cells have been completed!"
Cancel = True
End If
End With
End sub



how would I apply this to all the active sheets?
again massive thanks for your help!


  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,872
Default No save function if

Hi Owen,

Am Mon, 8 Dec 2014 19:20:33 +0000 schrieb Jeff Owen:

With Sheets("Sheet1")


change the line above to
With ActiveSheet


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 27
Default No save function if

On Monday, December 8, 2014 5:49:04 AM UTC-6, Jeff Owen wrote:
Hello all.

I'm looking to write something that will not allow the user to save the
sheet if things are not completed correctly. At the moment I have this
but it doesnt seem to work.

in G9 on sheet 1

=IF(ISBLANK(B9),"",IF(OR(ISBLANK(B9),ISBLANK(C9),I SBLANK(D9),ISBLANK(E9),ISBLANK(F9)),"Not
Complete","Complete"))

Which works fine. The issue is this......

Private Sub Workbook_BeforeSave(Cancel As Boolean)

If Sheet1.Range("G9").Value = "Not Complete" Then
MsgBox "Cannot save until ALL cells have been completed!"
Cancel = True
End If
End Sub

Any advice is greatly recieved.

Many thanks

Jeff




--
Jeff Owen

This should also take care of the careless spacebar

Dim c As Range
With Sheets("Sheet1")' most of us use application instead of worksheet.function
For Each c In .Range("b9:f9")
If Len(Application.Trim(c)) 0 Then mc = mc + 1
Next c
If mc 0 And mc < 5 Then
MsgBox "Cannot save until ALL cells have been completed!"
Cancel = True
application.goto .range("b9")

End If
End With
End Sub
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
Save result of IF function Rebbeca New Users to Excel 6 February 16th 09 01:44 PM
Save function in VB Hlewis Excel Programming 3 March 2nd 06 06:21 PM
Save As Function Hlewis Excel Programming 1 February 3rd 06 08:03 PM
Save and Save as Function gone Michael S. Excel Programming 2 June 27th 05 06:41 PM
'Save As' function / macro jpi_chicago Excel Programming 4 June 28th 04 10:42 PM


All times are GMT +1. The time now is 10:11 AM.

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

About Us

"It's about Microsoft Excel"