Advertisement

06.03.2008 at 12:58PM PDT, ID: 23454501
[x]
Attachment Details

Require data entry before save of an Excel sheet

Asked by jlm003 in Microsoft Office Suite, Microsoft Excel Spreadsheet Software

Tags: , ,

I have an Excel-2003 spreadsheet that has several fields but absolutely requires 4 specific fields to not be blank before "SAVE" or "PRINT".

I HAVE NO VB EXPERIECE WHATSOEVER SO PLEASE KEEP YOUR ANSWERS VERY SIMPLE!

I did a search on this topic, found a prior post regarding this subject and did a copy/paste of the VB code to my sheet. The result is that the code works BUT I can't save the sheet because I get an error message that the field is required. In this initial test I only used one field but eventually 3 more need to be validated.
 
The following code I what I copied from a prior post and which looks very complicate:

open the vb editor with ALT + F11
-in the left pane doubleclick thisworkbook icon
-then paste this code

Option Explicit

Private Sub Workbook_BeforeClose(Cancel As Boolean)
  if not CheckDateField then
    MsgBox "you need to fill in a end date to proceed"
    Cancel = true
  end if
End Sub

Private Sub Workbook_BeforePrint(Cancel As Boolean)
  if not CheckDateField then
    MsgBox "you need to fill in a end date to proceed"
    Cancel = true
  end if
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
  if not CheckDateField then
    MsgBox "you need to fill in a end date to proceed"
    Cancel = true
  end if
End Sub

Private Function CheckDateField() as Boolean
  CheckDateField=False
  If Worksheets(1).Range("C1").Value <> "" Then
    CheckDateField=True
  end if
End Function

-you've to change the line with Worksheets(1).Range("C1").Value
-to the field you need to check
-then save and close the editor

then try it out

 Start Free Trial
[+][-]06.03.2008 at 01:10PM PDT, ID: 21704045

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.04.2008 at 07:02AM PDT, ID: 21710184

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.04.2008 at 07:20AM PDT, ID: 21710362

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.04.2008 at 07:28AM PDT, ID: 21710443

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.04.2008 at 07:30AM PDT, ID: 21710469

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.04.2008 at 07:36AM PDT, ID: 21710545

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.04.2008 at 07:57AM PDT, ID: 21710765

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Office Suite, Microsoft Excel Spreadsheet Software
Tags: Microsoft, Office, Excel 2003
Sign Up Now!
Solution Provided By: zorvek
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628