IF formula for page numbers

Posted on 2011-10-12
Last Modified: 2012-05-12
Hi Experts,
in cel P2 on 5 sheets in a row there is a page of page numbers. eg 1 of 1 or 1 of 3 etc.

I want to do an if formula for each of the P2 cells....
sht1    P2=  if sht2 C4="value" then "1 of 2" or if sht3 C4="value" then "1 of 3" etc etc

I think you get the idea. if sht3 C4 had a value but sht4 didnt then:
sht1 P2= "1 of 3"
sht2 P2= "2 of 3"
sht3 P2= "3 of 3"

Then once that is complete i would like to have a button with a macro to make a single PDF for with pages for sheets - sht1 & sht2 & sht3 with the PDF saved as the job name "sht1 C2" then a space and then the date in "sht1 J2"

Is this possible?? each of the sht's is the size of and A4 landscape.


Question by:RobJanine
    LVL 3

    Expert Comment

    something like this?
    ="1 of " & IF('Sht 2 - Table 1'!C4="";1;IF('Sht 3 - Table 1'!C4="";2;IF('Sht 4 - Table 1'!C4="";3;IF('Sht 5 - Table 1'!C4="";4;5))))
    LVL 3

    Accepted Solution

    and here your makro...
    just make a button and connect it
    and you have to set the pdf printer you use.
    In case you don't know what it's called, start the macro recorder in excel and start to print manually, select the pdf printer of your choice and stop the macro recording process and look in the recorded macro for the printer of your choice :-)

    Sub PrintToPDF()

    Dim toPage As Integer

    toPage = 1
    If (ActiveWorkbook.Sheets("Sht 2 - Table 1").Cells(4, 3) <> "") Then
        toPage = toPage + 1
        If (ActiveWorkbook.Sheets("Sht 3 - Table 1").Cells(4, 3) <> "") Then
            toPage = toPage + 1
            If (ActiveWorkbook.Sheets("Sht 4 - Table 1").Cells(4, 3) <> "") Then
                toPage = toPage + 1
                If (ActiveWorkbook.Sheets("Sht 5 - Table 1").Cells(4, 3) <> "") Then
                    toPage = toPage + 1
                End If
            End If
        End If
    End If

    Application.ActivePrinter = "PUT YOUR PDF PRINTER HERE!!!"
    ActiveWindow.SelectedSheets.PrintOut From:=1, To:=toPage, Copies:=1, Collate:=True

    End Sub

    Author Comment

    will this work for not printing. I want it to make a pdf and save it in a folder...or email to some. Not print.

    LVL 3

    Expert Comment

    as far as I know excel can't create pdfs directly, but you can install a "virtual" pdf printer which will work just like any regular printer except no paper comes out but a safe to disc dialog will appear where you can "print" a pdf to...

    a free pdf printer (you can use that in any application where you can print by the way) is this one for example:
    It's german but it's running like a charm. But there are many free alternatives for this.

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
    How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
    The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
    This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now