Solved

Print specified range of cells content in a spreadsheet

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

Expert Comment

by:Ingeborg Hawighorst
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:Ingeborg Hawighorst
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
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 create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

697 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