Hello
I have Excel 2010 and I am trying to disable the print funtion until certain cells (AO6, F9, AO9, BD0, etc) are filled out.
I found this code on the website, but does not work for me...
Is there someting i am missing?Private Sub Workbook_BeforePrint(Cancel As Boolean) If IsEmpty(Worksheets("HRM").Range("bj2")) Then Cancel = True Msg = MsgBox("Please complete cells to continue ", vbOKOnly) Else If Not IsEmpty(Worksheets("HRM").Range("bj2")) Then Cancel = False End If End If End Sub
TY
Last edited by toddp; 09-21-2011 at 01:56 PM.
Hi Todd. Welcome to the forum.
As per forum rules (you can click the link in the menu bar above and read through them), please EDIT your post above, and add code tags around you posted code as demonstrated in my signature below.
I'll take a look at your code after that. Thanks.Like this...
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
“None of us is as good as all of us” - Ray Kroc
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
solved with this:
Private Sub Workbook_BeforePrint(Cancel As Boolean) If IsEmpty([AO6]) Or IsEmpty([F9]) Or IsEmpty([AO9]) Or IsEmpty([BD9]) Or IsEmpty([K10]) Or IsEmpty([BC10]) Or IsEmpty([K12]) Or IsEmpty([J16]) Or IsEmpty([H17]) Or IsEmpty([AJ17]) Or IsEmpty([AY16]) Or IsEmpty([C85]) Then Cancel = True MsgBox ("FILL OUT ALL YELLOW FIELDS !!!!!") End If End Sub
Simplest way is to define a Named Range in the worksheet that is the cells to check, Then just use
Option Explicit 'PrintCells is a Named Range on Sheet1 Private Sub Workbook_BeforePrint(Cancel As Boolean) If Application.WorksheetFunction.CountA(Sheet1.Range("PrintCells")) < _ Sheet1.Range("PrintCells").Cells.Count Then Cancel = True MsgBox ("FILL OUT ALL YELLOW FIELDS !!!!!") End If End Sub
Last edited by royUK; 09-21-2011 at 01:57 PM.
Hope that helps.
RoyUK
--------
If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need
For Excel Tips & Solutions, free examples and tutorials why not check out my downloads
New members please read & follow the Forum Rules
Remember to mark your questions Solved and rate the answer(s)
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks