Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Bob Bob is offline
external usenet poster
 
Posts: 972
Default Requiring multiple cells to be populated before allowing Save

I found the following code snippet that will not allow a user to save a
worksheet until cell M2 has been populated:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If IsEmpty(Sheets("Sheet1").Range("M2").Value) Then
Cancel = True
MsgBox ("The workbook cannot be saved until cell M2 has been
populated.")
End If
End Sub

Being relatively new to VBA, can someone tell me how to modify the code
above so that a range (M2:M25) must be populated before a user is allowed to
save the worksheet?

I tried changing the 2nd code line above to:

If IsEmpty(Sheets("Sheet1").Range("M2:M25").Value) Then

but that didn't work. Any help would be greatly appreciated.

Thanks,
Bob

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 25
Default Requiring multiple cells to be populated before allowing Save

Hi Bob,

You could try:

For Each iCell In Sheets("Sheet1").Range("M2:M25")
If IsEmpty(Sheets("Sheet1").Range(iCell.Address)) Then
Cancel = True
MsgBox ("The workbook cannot be saved until cell " & iCell.Address & " has
been populated.")
Exit Sub
End If
Next iCell


Alan

--
Message posted via http://www.officekb.com

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Bob Bob is offline
external usenet poster
 
Posts: 972
Default Requiring multiple cells to be populated before allowing Save

Hi Alan,

Thanks for your solution. I assume I should precede your code with:

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

Is that true?

Thanks again for your help!
Bob


"Alan McQuaid via OfficeKB.com" wrote:

Hi Bob,

You could try:

For Each iCell In Sheets("Sheet1").Range("M2:M25")
If IsEmpty(Sheets("Sheet1").Range(iCell.Address)) Then
Cancel = True
MsgBox ("The workbook cannot be saved until cell " & iCell.Address & " has
been populated.")
Exit Sub
End If
Next iCell


Alan

--
Message posted via http://www.officekb.com


  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 22,906
Default Requiring multiple cells to be populated before allowing Save

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

Alan's code here

End Sub

Entered in Thisworkbook module, not a sheet or general module.


Gord Dibben MS Excel MVP

On Tue, 18 Aug 2009 11:24:01 -0700, Bob
wrote:

Hi Alan,

Thanks for your solution. I assume I should precede your code with:

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

Is that true?

Thanks again for your help!
Bob


"Alan McQuaid via OfficeKB.com" wrote:

Hi Bob,

You could try:

For Each iCell In Sheets("Sheet1").Range("M2:M25")
If IsEmpty(Sheets("Sheet1").Range(iCell.Address)) Then
Cancel = True
MsgBox ("The workbook cannot be saved until cell " & iCell.Address & " has
been populated.")
Exit Sub
End If
Next iCell


Alan

--
Message posted via http://www.officekb.com



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
Multiple question requiring asistance please NoodNutt Excel Worksheet Functions 4 August 20th 08 01:21 AM
Requiring Cell Content on Save The Chad Excel Discussion (Misc queries) 1 July 3rd 08 12:06 AM
Requiring data in certain cells jerminski73 Excel Worksheet Functions 2 November 21st 07 02:03 PM
Control + Shift + Up/Down not allowing me to select multiple cells. [email protected] Excel Discussion (Misc queries) 1 April 5th 07 02:31 PM
Macro for Not Allowing to Save without first completing fields HROBERTSON Excel Discussion (Misc queries) 1 January 5th 07 03:12 PM


All times are GMT +1. The time now is 09:05 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"