sarahlynnette
New Member
- Joined
- May 14, 2014
- Messages
- 6
Hi, I'm new to VBA and most of what I have learned has been through Google and I have found a lot on this site. I am trying to write a code that will prevent the user from printing the worksheet if two specific cells are blank. I have tried the following codes, none of which have worked. The first code didn't work due to once the first cell is completed it won't check the others and prevent printing. The second allows the worksheet to print regardless of whether it is blank or not. Could this be because I have a formula in those cells?
Private Sub Workbook_BeforePrint(Cancel As Boolean)
With Sheets("JULY")
If .Range("I2") = "" Then
.Select
.Range("I2").Select
MsgBox "Please enter a dollar amount into the Rate/Hr field"
If .Range("F40") = "" Then
.Select
.Range("F40").Select
MsgBox "Please enter time worked into the proper days"
End If
End With
End Sub
Private Sub Workbook_BeforePrint(Cancel As Boolean)
If ActiveSheet.Name = "JULY" Then
If Application.WorksheetFunction.CountA(Sheets("JULY").Range("F40, I2")) < 2 Then
MsgBox "One or more of the required fields is blank."
Cancel = True
End If
End If
End Sub
Private Sub Workbook_BeforePrint(Cancel As Boolean)
With Sheets("JULY")
If .Range("I2") = "" Then
.Select
.Range("I2").Select
MsgBox "Please enter a dollar amount into the Rate/Hr field"
If .Range("F40") = "" Then
.Select
.Range("F40").Select
MsgBox "Please enter time worked into the proper days"
End If
End With
End Sub
Private Sub Workbook_BeforePrint(Cancel As Boolean)
If ActiveSheet.Name = "JULY" Then
If Application.WorksheetFunction.CountA(Sheets("JULY").Range("F40, I2")) < 2 Then
MsgBox "One or more of the required fields is blank."
Cancel = True
End If
End If
End Sub