Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Excel worksheets consolidated for printing

Posted on 2011-03-16
3
Medium Priority
?
326 Views
Last Modified: 2012-05-11
I'm creating a punch list in excel with each worksheet representing a different room in an apartment. When finished  I would like to do is create pdf of the consolidated worksheets. But I would also like that consolidation to be only the worksheets that contain entries in the punch list items column that exists on each worksheet. I'm trying to avoid a pdf that contains empty worksheets.
 Would it be easier to have a button that would allow me to select which sheets I want? Could the code run through each worksheet for a specific range, and if the cells in that range contain any data, add that worksheet to the pdf? I have a couple of driver options for printing to pdf.
0
Comment
Question by:wlamore
  • 3
3 Comments
 
LVL 19

Expert Comment

by:Arno Koster
ID: 35149237
printing to pdf is best done using a regular "print-to-pdf" driver, any will do.

Easiest way to do this is to browse through all worksheets, determine for each one wether or not it is to be printed, and then print them out.
This is not a very difficult thing to do in a macro !
Best way would be to assign this macro to a key combination so that you can start the macro just by pressing some keys.
0
 
LVL 19

Accepted Solution

by:
Arno Koster earned 1000 total points
ID: 35149345
Public Sub print_to_pdf()

Dim ws As Worksheet
Dim to_be_printed()

    ReDim to_be_printed(1)
    
    '-- loop through worksheets
    For Each ws In Worksheets
    
        '-- if more than 1 rows are used, worksheet is considered filled with data
        If ws.UsedRange.Rows.Count > 1 Then
            ReDim Preserve to_be_printed(UBound(to_be_printed) + 1)
            to_be_printed(UBound(to_be_printed) - 1) = ws.Name
        End If
    
    Next ws
    ReDim Preserve to_be_printed(UBound(to_be_printed) - 1)
    
    '-- print out the sheets that need to be printed
    sheets(to_be_printed).PrintOut
    
End Sub

Open in new window

0
 
LVL 19

Expert Comment

by:Arno Koster
ID: 35149356
Best would be to also add
option base 1

Open in new window


as the first line of the module containing the macro
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
Progress
Loops Section Overview

885 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