Print Table

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Print Table

Post by adam »

Hi anyone,

How could I write a code that would print all the visible rows and columns of the table.
My table has headers in row 10 of sheet "report".
It has data from column B to L. (column B is a hidden column).
I have data in row 7 also which is not part of the table but which still I want to print with the table.

Any help on this would be kindly appreciated.

Thanks in advance.
Best Regards,
Adam

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: Print Table

Post by Rudi »

See if this does what you need.
Hidden rows do not print, so there is no need to determine what is hidden or not.

Code: Select all

Sub PrintCustom()
Dim rg As Range

    Set rg = Range("C10").CurrentRegion.Offset(-3).Resize(Range("C10").CurrentRegion.Rows.Count + 3)
    rg.PrintPreview '<< Change to rg.PrintOut if you want to print immediately
End Sub
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Print Table

Post by adam »

Where should the sheet name be placed in this code?
Best Regards,
Adam

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: Print Table

Post by Rudi »

Change the sheet name where indicated...

Code: Select all

Sub PrintCustom()
Dim sh As Worksheet
Dim rg As Range

Const shName = "Test" '<< Change sheet name here...

    Set sh = Worksheets(shName)
    Set rg = sh.Range("C10").CurrentRegion.Offset(-3).Resize(sh.Range("C10").CurrentRegion.Rows.Count + 3)
    rg.PrintPreview '<< Change to rg.PrintOut if you want to print immediately
End Sub
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Print Table

Post by adam »

Thanks for the help Rudi. The code works fine now.
Best Regards,
Adam