Results 1 to 2 of 2

VB Code to Print Visible Cells

This is a discussion on VB Code to Print Visible Cells within the Excel Questions forums, part of the Question Forums category; Is there a macro I can write that will print cells with visible data. I have worksheet that has about ...

  1. #1
    New Member
    Join Date
    Jul 2007
    Location
    STL
    Posts
    32

    Default VB Code to Print Visible Cells

    Is there a macro I can write that will print cells with visible data. I have worksheet that has about 1000 rows with formulas but currently only has 7 rows with visible data. I'd like to have a print button that would allow the users to just press it and print the visible cells only. I've tried building a macro that, if you select the bottom left cell of the visible worksheet, it would highlight to the top and to the right, go to print, print selection and so on. I don't know how to write the code so that is would select up to cell "A1" and then over to the right to cell "S1"...

    Any help on this or a different method?

  2. #2
    Board Regular
    Join Date
    Feb 2003
    Location
    Luton, England.
    Posts
    8,108

    Default Re: VB Code to Print Visible Cells

    I think this is what you want.
    Code:
    '============================================================================
    '- CHANGE PRINT RANGE TO INCLUDE TOP OF SHEET DOWN TO ACTIVE CELL
    '- select a cell anywhere in the bottom row and run the macro
    '- could be put into ..  Private Sub Worksheet_BeforeDoubleClick
    '============================================================================
    Sub test()
        Dim MyRow As Long
        Dim PrintAreaAddress As String
        '------------------------------------------------------------------------
        MyRow = ActiveCell.Row
        PrintAreaAddress = Range(Cells(1, "A"), Cells(MyRow, "S")).Address
        ActiveSheet.PageSetup.PrintArea = PrintAreaAddress
    End Sub
    Regards
    BrianB (using XL2003 & 2010)
    Most problems occur from starting at the wrong place.
    Use a cup of coffee to speed up all Windows processes.
    It is easy until you know how.
    **FORMATTED/COMMENTED CODE IS MORE LIKELY TO GET A REPLY

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


DMCA.com