Solved

Print specified range of cells content in a spreadsheet

Posted on 2011-02-19
5
463 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
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

Expert Comment

by:teylyn
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

Expert Comment

by:teylyn
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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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 …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

932 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