PC Review


Reply
Thread Tools Rate Thread

Check Worksheet When Workbook Is Saved

 
 
=?Utf-8?B?Q2xhcmU=?=
Guest
Posts: n/a
 
      10th Oct 2007
Hi, could someone tell me how to do this in vba ?

When a user tries to save the workbook, for Sheet1 if any cell in column A
(A3 until the last row) equals "3" or column B (B3 until the last row)
equals "Calculus" then prevent the workbook from being saved & prompt a
msgbox if the corresponding cell in column C , F & H is blank.

Thanks !

Rgds,
Clare
 
Reply With Quote
 
 
 
 
JW
Guest
Posts: n/a
 
      10th Oct 2007
So, all of those conditions must be met, correct? If so, place this
in the ThisWorkbook module of the applicable workbook.
Private Sub Workbook_BeforeSave(ByVal SaveAsUI _
As Boolean, Cancel As Boolean)
Dim lRow As Long
With Sheets("Sheet1")
lRow = .Cells.Find(what:="*", _
After:=.Cells(1, 1), _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
For i = 3 To lRow
If .Cells(i, 1).Text = "3" Or _
.Cells(i, 2).Text = "Calculus" Then
If IsEmpty(.Cells(i, 3)) And _
IsEmpty(.Cells(i, 6)) And _
IsEmpty(.Cells(i, 8)) Then
Cancel = True
MsgBox "Your message here"
Exit For
End If
End If
Next i
End With
End Sub
Clare wrote:
> Hi, could someone tell me how to do this in vba ?
>
> When a user tries to save the workbook, for Sheet1 if any cell in column A
> (A3 until the last row) equals "3" or column B (B3 until the last row)
> equals "Calculus" then prevent the workbook from being saved & prompt a
> msgbox if the corresponding cell in column C , F & H is blank.
>
> Thanks !
>
> Rgds,
> Clare


 
Reply With Quote
 
=?Utf-8?B?Q2xhcmU=?=
Guest
Posts: n/a
 
      15th Oct 2007
Sorry for late reply. I tested out the code & it worked well.

Some more questions on this code:
1) If I don't want to prevent the user from saving, but just prompt them
which row(s) that is not fulfilling the criteria, allow them to click "OK",
then prompt them to give them a choice to save the workbook or don't save and
continue working with the workbook.... how can this be done ?
2) Besides the criteria already in effect, if any cell in column A equals 1
AND the corresponding cell in column D is more than 500, then prompt the user
on which row(s) is not fulfilling the criteria, allow them to click "OK",
then prompt them to give them a choice to save the workbook or don't save and
continue working with the workbook.

Appreciate any help. Thanks!!

"JW" wrote:

> So, all of those conditions must be met, correct? If so, place this
> in the ThisWorkbook module of the applicable workbook.
> Private Sub Workbook_BeforeSave(ByVal SaveAsUI _
> As Boolean, Cancel As Boolean)
> Dim lRow As Long
> With Sheets("Sheet1")
> lRow = .Cells.Find(what:="*", _
> After:=.Cells(1, 1), _
> SearchOrder:=xlByRows, _
> SearchDirection:=xlPrevious).Row
> For i = 3 To lRow
> If .Cells(i, 1).Text = "3" Or _
> .Cells(i, 2).Text = "Calculus" Then
> If IsEmpty(.Cells(i, 3)) And _
> IsEmpty(.Cells(i, 6)) And _
> IsEmpty(.Cells(i, 8)) Then
> Cancel = True
> MsgBox "Your message here"
> Exit For
> End If
> End If
> Next i
> End With
> End Sub
> Clare wrote:
> > Hi, could someone tell me how to do this in vba ?
> >
> > When a user tries to save the workbook, for Sheet1 if any cell in column A
> > (A3 until the last row) equals "3" or column B (B3 until the last row)
> > equals "Calculus" then prevent the workbook from being saved & prompt a
> > msgbox if the corresponding cell in column C , F & H is blank.
> >
> > Thanks !
> >
> > Rgds,
> > Clare

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create new workbook and new worksheet and close. Worksheet not saved Patrick Microsoft Excel Programming 1 25th Jul 2009 07:00 PM
Check for worksheet in closed workbook Les Microsoft Excel Programming 4 3rd Dec 2007 04:45 PM
Worksheet saved out as new workbook =?Utf-8?B?VE9NQg==?= Microsoft Excel Programming 3 14th Nov 2007 07:53 PM
can I hyperlink to a worksheet tab in workbook saved as html? =?Utf-8?B?bGFydW5l?= Microsoft Excel Misc 0 17th May 2006 04:53 PM
When saving workbook only the first worksheet gets saved. Debutante Microsoft Excel Worksheet Functions 5 18th Dec 2004 01:31 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:48 AM.