+ Reply to Thread
Results 1 to 4 of 4

Thread: Disable printing in Excel 2010 unless cell(s) are filled out

  1. #1
    Registered User
    Join Date
    09-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    3

    Disable printing in Excel 2010 unless cell(s) are filled out

    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...

                  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
    Is there someting i am missing?


    TY
    Last edited by toddp; 09-21-2011 at 01:56 PM.

  2. #2
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,224

    Re: Disable printing in Excel 2010 unless cell(s) are filled out

    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.

    Like this...
    I'll take a look at your code after that. Thanks.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon 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!)

  3. #3
    Registered User
    Join Date
    09-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Disable printing in Excel 2010 unless cell(s) are filled out

    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

  4. #4
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,639

    Re: Disable printing in Excel 2010 unless cell(s) are filled out

    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)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0