Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print Excel Sheet on condition that mandatory cells are filled 1

Status
Not open for further replies.

kinselas

IS-IT--Management
Aug 4, 2002
60
AU
Is it possible to print an Excel Spreadsheet ONLY on condition that all mandatory cells are entered.
I am using Excel 2000
 
Yes. You can use VBA to do what you want.

Right-click on a worksheet tab and select View Code. Then in the left-hand window of the VBA screen, click on "ThisWorkbook" and paste in the following code for a demo:
Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
  MsgBox "Checking for all required data"
  Cancel = True
End Sub
A more production-oriented example would use a function and look like this:
Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
  Cancel = CheckForMissingData()
End Sub
And then in a code module (Menu: Insert/Module) you can do something like this:
Code:
Option Explicit
Function CheckForMissingData() As Boolean
  CheckForMissingData = False
  If Range("B2") = "" _
      Or Range("C2") = "" _
      Or Range("D2") = "" Then
    CheckForMissingData = True
    MsgBox ("Missing some required data")
  End If
End Function


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top