Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Auditing Excel sheet - Message Box on exiting excel

Greetings,

I am new to programming in excel. I have a requirement where a excel
needs to be audited for certain tasks. This is what I need to achieve

Requirement:

"Column A in excel1 can only have one of the 3 statuses: FAIL, OTHER
or SUCCESS.
If Column A is filled with either FAIL or OTHER status value, then
Column B should never be kept empty. It means that Column B should
always have a value and that respective cell should never be left
empty. Also, Column A cannot have any other status except the above 3"

Work done till now: I have already implemented the functionality where
if the Column B is left blank, the respective cell gets highlighted
letting user know that he needs to fill in that cell. However,
sometimes user might ignore and might try to save and close excel
without fully confirming to above requirement.

Main Objective: To come up with a code in excel that will display a
mesasge box to user (when he tries to save and exit the excel) letting
him know if the above main Requirement gets violated.

Can anyone please help me here.

TIA
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Auditing Excel sheet - Message Box on exiting excel

Hi,

Try this . ALT+F11 to open vb editor, double click 'ThisWorkbook' and paste
the code below in. Change MySheet to the name of your data sheet. Before a
save it checks that only your legal values are in column A and if column A is
legal then column B must be populated.

I don't see how checking this before close helps (it can be done) but if you
don't allow an illegal save then an illegal close isn't possible.


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim MySheet As String, lastrow As Long
MySheet = "Sheet1"
lastrow = Sheets(MySheet).Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Sheets(MySheet).Range("A1:A" & lastrow)
For Each c In MyRange
Select Case UCase(c)
Case "FAIL", "OTHER", "SUCCESS"
If c.Offset(, 1).Value = "" Then
MsgBox "You must populate " & c.Offset(, 1).Address
Cancel = True
Exit For
End If
Case Else
MsgBox "Illegal value in " & c.Address
Cancel = True
Exit For
End Select
Next
End Sub

Mike

"test" wrote:

Greetings,

I am new to programming in excel. I have a requirement where a excel
needs to be audited for certain tasks. This is what I need to achieve

Requirement:

"Column A in excel1 can only have one of the 3 statuses: FAIL, OTHER
or SUCCESS.
If Column A is filled with either FAIL or OTHER status value, then
Column B should never be kept empty. It means that Column B should
always have a value and that respective cell should never be left
empty. Also, Column A cannot have any other status except the above 3"

Work done till now: I have already implemented the functionality where
if the Column B is left blank, the respective cell gets highlighted
letting user know that he needs to fill in that cell. However,
sometimes user might ignore and might try to save and close excel
without fully confirming to above requirement.

Main Objective: To come up with a code in excel that will display a
mesasge box to user (when he tries to save and exit the excel) letting
him know if the above main Requirement gets violated.

Can anyone please help me here.

TIA

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Auditing Excel sheet - Message Box on exiting excel

I forgt to include a test for empty cells in column a

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim MySheet As String, lastrow As Long
MySheet = "Sheet1"
lastrow = Sheets(MySheet).Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Sheets(MySheet).Range("A1:A" & lastrow)
For Each c In MyRange
Select Case UCase(c)
Case "FAIL", "OTHER", "SUCCESS"
If c.Offset(, 1).Value = "" Then
MsgBox "You must populate " & c.Offset(, 1).Address
Cancel = True
Exit For
End If
Case Else
If c.Value < "" Then
MsgBox "Illegal value in " & c.Address
Cancel = True
Exit For
End If
End Select
Next
End Sub


Mike

"Mike H" wrote:

Hi,

Try this . ALT+F11 to open vb editor, double click 'ThisWorkbook' and paste
the code below in. Change MySheet to the name of your data sheet. Before a
save it checks that only your legal values are in column A and if column A is
legal then column B must be populated.

I don't see how checking this before close helps (it can be done) but if you
don't allow an illegal save then an illegal close isn't possible.


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim MySheet As String, lastrow As Long
MySheet = "Sheet1"
lastrow = Sheets(MySheet).Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Sheets(MySheet).Range("A1:A" & lastrow)
For Each c In MyRange
Select Case UCase(c)
Case "FAIL", "OTHER", "SUCCESS"
If c.Offset(, 1).Value = "" Then
MsgBox "You must populate " & c.Offset(, 1).Address
Cancel = True
Exit For
End If
Case Else
MsgBox "Illegal value in " & c.Address
Cancel = True
Exit For
End Select
Next
End Sub

Mike

"test" wrote:

Greetings,

I am new to programming in excel. I have a requirement where a excel
needs to be audited for certain tasks. This is what I need to achieve

Requirement:

"Column A in excel1 can only have one of the 3 statuses: FAIL, OTHER
or SUCCESS.
If Column A is filled with either FAIL or OTHER status value, then
Column B should never be kept empty. It means that Column B should
always have a value and that respective cell should never be left
empty. Also, Column A cannot have any other status except the above 3"

Work done till now: I have already implemented the functionality where
if the Column B is left blank, the respective cell gets highlighted
letting user know that he needs to fill in that cell. However,
sometimes user might ignore and might try to save and close excel
without fully confirming to above requirement.

Main Objective: To come up with a code in excel that will display a
mesasge box to user (when he tries to save and exit the excel) letting
him know if the above main Requirement gets violated.

Can anyone please help me here.

TIA

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Auditing Excel sheet - Message Box on exiting excel

On Feb 28, 6:29*pm, Mike H wrote:
I forgt to include a test for empty cells in column a

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim MySheet As String, lastrow As Long
MySheet = "Sheet1"
lastrow = Sheets(MySheet).Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Sheets(MySheet).Range("A1:A" & lastrow)
For Each c In MyRange
* * Select Case UCase(c)
* * * * Case "FAIL", "OTHER", "SUCCESS"
* * * * If c.Offset(, 1).Value = "" Then
* * * * * * MsgBox "You must populate " & c.Offset(, 1).Address
* * * * * * Cancel = True
* * * * * * Exit For
* * * * End If
* * * * *Case Else
* * * * * * If c.Value < "" Then
* * * * * * MsgBox "Illegal value in " & c.Address
* * * * * * Cancel = True
* * * * * * Exit For
* * * * * * End If
* * End Select
Next
End Sub

Mike



"Mike H" wrote:
Hi,


Try this . ALT+F11 to open vb editor, double click 'ThisWorkbook' and paste
the code below in. Change MySheet to the name of your data sheet. Before a
save it checks that only your legal values are in column A and if column A is
legal then column B must be populated.


I don't see how checking this before close helps (it can be done) but if you
don't allow an illegal save then an illegal close isn't possible.


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim MySheet As String, lastrow As Long
MySheet = "Sheet1"
lastrow = Sheets(MySheet).Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Sheets(MySheet).Range("A1:A" & lastrow)
For Each c In MyRange
* * Select Case UCase(c)
* * * * Case "FAIL", "OTHER", "SUCCESS"
* * * * If c.Offset(, 1).Value = "" Then
* * * * * * MsgBox "You must populate " & c.Offset(, 1).Address
* * * * * * Cancel = True
* * * * * * Exit For
* * * * End If
* * * * *Case Else
* * * * * * *MsgBox "Illegal value in " & c.Address
* * * * * * *Cancel = True
* * * * * * *Exit For
* * End Select
Next
End Sub


Mike


"test" wrote:


Greetings,


I am new to programming inexcel. I have a requirement where aexcel
needs to be audited for certain tasks. This is what I need to achieve


Requirement:


"Column A in excel1 can only have one of the 3 statuses: FAIL, OTHER
or SUCCESS.
If Column A is filled with either FAIL or OTHER status value, then
Column B should never be kept empty. It means that Column B should
always have a value and that respective cell should never be left
empty. Also, Column A cannot have any other status except the above 3"


Work done till now: I have already implemented the functionality where
if the Column B is left blank, the respective cell gets highlighted
letting user know that he needs to fill in that cell. However,
sometimes user might ignore and might try to save and closeexcel
without fully confirming to above requirement.


Main Objective: To come up with a code inexcelthat will display a
mesasge box to user (when he tries to save and exit theexcel) letting
him know if the above main Requirement gets violated.


Can anyone please help me here.


TIA- Hide quoted text -


- Show quoted text -


Thanks Matt/Mike. Its working as expected.
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
Message Box on exiting workbook cufc1210 Excel Discussion (Misc queries) 1 September 30th 09 02:39 PM
VBAProject Password message appears when exiting Excel GDCross Excel Programming 5 March 7th 08 09:23 AM
How to protect sheet, yet allow Auditing?€Ž Phil Davy Excel Discussion (Misc queries) 3 July 31st 07 08:22 PM
how do i get a pop up message on saving or exiting a document? babyboos Excel Worksheet Functions 3 February 2nd 07 10:58 PM
EXCEL FORMAT PROBLEM WHEN SENDING EXCEL SHEET AS MESSAGE BODY IN . P.S.Sodha Excel Discussion (Misc queries) 0 April 2nd 05 01:53 PM


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