VB Code to Print Visible Cells

estrauss22

New Member
Joined
Jul 5, 2007
Messages
32
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?
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
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
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top