?
Solved

Print specified range of cells content in a spreadsheet

Posted on 2011-02-19
5
Medium Priority
?
469 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 2

Expert Comment

by:mscanlon06851
ID: 34933931
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
ID: 34935794
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
ID: 34935834
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
ID: 34935850
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 2000 total points
ID: 34935978
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
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…

777 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