Solved

Print specified range of cells content in a spreadsheet

Posted on 2011-02-19
5
458 Views
Last Modified: 2012-06-27
I want to give a print out to local printer that will print the given range of cells content with the same style guide/Format in the spreadsheet.

EX: If i have B5:G20 is the range of cell content with given format/style property to be printed at a click of command button through local printer
0
Comment
Question by:srikanthv2322
  • 3
  • 2
5 Comments
 
LVL 2

Expert Comment

by:mscanlon06851
Comment Utility
See if this does the trick for you.

I'm assuming you have a specific page in a specific workbook to which you want to add the command button and that you will be reusing this page for this purpose repeatedly.

First, embed a control button in the upper left hand corner of the page

-right-click on a blank section in the toolbar area at the top of the page (to display a list of all toolbars)
-click on "Control Toolbox"  if it's not already checked (to display the list of available toolbars)
-(drag the toolbar to top of the screen to "dock" it, if you want)
-click on the "command button" control on the Control Toolbox toolbar
-drag the button to wherever you want to place it permanently
-right-click on the command button
-click Properties
-change the Name value to "cmdPrintSelection"
-change the Caption value to "Print Selection"
-close the Properties window
-expand the size of the button, if text doesn't fit

Next, add code to the button to generate the printout

-double-click on the Print Selection command button (to open a code window in the VB Editor)
-immedidately below the line that says "Private Sub cmdPrintSelection_Click()", paste in the following code
   
    Dim Response As Integer
   
    Response = _
        MsgBox("Print cells " & Chr(10) & Chr(10) & Selection.Address & " ?", _
        vbOKCancel, "Print Cells")
    If Response = vbCancel Then
        Exit Sub
    End If
   
    ActiveSheet.PageSetup.PrintArea = Selection.Address
    ActiveWindow.SelectedSheets.PrintOut
    ActiveSheet.PageSetup.PrintArea = ""

-be sure the words "End Sub" follow the above code
-return to the workbook
-click on the first icon on the Control Toolbox toolbar (to "Exit Design Mode")
-save the workbook

To print a range of cells:

-using the mouse, select the range of cells to be printed
-click the "Print Selection" button

Note that the report will be sent directly to the default printer, so be sure the workbook is pointing to the correct printer prior to the first time you click on the command button.

Or, you can just use the attachment
 PrintSelection.xls
0
 
LVL 50

Expert Comment

by:teylyn
Comment Utility
Why do you need a macro do do that?

Just define the cells you want to print as the Print Area and whenever you want to print them, click the Print button that's already a part of the user interface.

What am I not getting?

cheers, teylyn
0
 
LVL 2

Expert Comment

by:mscanlon06851
Comment Utility
Your point is well taken, teylyn.

My verbose answer was in response to the stated request for a command button that would  perform the operation with a single click.   If I mis-interpreted the intent of the request, then I cheerfully concur with -- and recommend -- your solution.

Regards,

ms


0
 
LVL 50

Expert Comment

by:teylyn
Comment Utility
Well, there could be more to it than I see. I have this little private mission to discourage re-inventing the wheel with macros when Excel has the functionality and  buttons already in place.

If a Print Area is already set to a different range, and the objective is to use a button to print a different range, disregarding the Print Area, I guess the request -- and the solution suggested -- makes perfect sense.

cheers, teylyn
0
 
LVL 2

Accepted Solution

by:
mscanlon06851 earned 500 total points
Comment Utility
teylyn, I concur with and support your mission.

At the same time, I'm reluctant to second-guess those who seek assistance through Experts Exchange.  If srikanthv2322 is looking for a single-click mechanism for printing a range of cells,  I can't help feeling it would be somewhat presumptuous of me to deny it to him simply because I prefer that he perform the steps manually.

I assure you that I will have absolutely no problem at all if srikanthv2322 opts to use the method you suggest.  I proffered my solution only in response to my (probably erroneous)  intreptation of the original request.

srikanthv2322, I apologize to you for these digressions.   I trust that among the solutions we have provided, you will find one that meets your needs.  

Regards,

MS
0

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

Join & Write a Comment

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

772 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

9 Experts available now in Live!

Get 1:1 Help Now