Solved

Excel worksheets consolidated for printing

Posted on 2011-03-16
3
318 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:akoster
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:
akoster earned 250 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:akoster
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

760 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

19 Experts available now in Live!

Get 1:1 Help Now