deny printing for certain blank cells

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do I make a macro button that will return the user back to the
spreadsheet if certain cells are not filled in?

Thanks,
Tim
 
Use the BeforePrint event in the ThisWorkbook module. Are you familiar with
this?
Here is some sample code:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
'BOTH cells must contain data before printing-
If Application.WorksheetFunction.CountA(Range("A1,C25")) < 2 Then
Cancel = True
MsgBox "A1 and C25 must have values"
End If
End Sub

--
 
Add this code to the ThisWorkbook code:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If Worksheets("Sheet1").Cells(1, 1) = "" Then
MsgBox "Cancelled"
Cancel = True
End If
End Sub

If Cell A1 on Sheet1 is empty then the print job will be cancelled.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top