ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Show only Print_area range (https://www.excelbanter.com/excel-programming/360516-show-only-print_area-range.html)

Gwen[_3_]

Show only Print_area range
 
Hello,

I need to have a macro that hides all the rows and colums that is not part
of a print area on a sheet.

My print area has graphs, and I tried to hide the rows or columns that
contain the datas, and the graphs disappear.
Is there a solution for this?

Thanks.



Norman Jones

Show only Print_area range
 
Hi Gwen,

If you ensure that the graph data cells are above, or to the left, of the
print area, perhaps try something like:

'=============
Public Sub Tester()
Dim WB As Workbook
Dim SH As Worksheet
Dim MyPrintRng As Range
Dim FirstRow As Long
Dim FirstCol As Long

Set WB = ThisWorkbook '<<==== CHANGE
Set SH = WB.Sheets(1) '<<==== CHANGE

Set MyPrintRng = Range(SH.PageSetup.PrintArea)
SH.ScrollArea = ""

With MyPrintRng
Application.Goto .Cells(1), Scroll:=True
Worksheets(1).ScrollArea = .Address
FirstRow = .Row + .Rows.Count
FirstCol = .Column + .Columns.Count
End With

With SH
.Rows(FirstRow & ":" & Rows.Count).Hidden = True
.Columns(FirstCol).Resize(1, Columns.Count - _
FirstCol + 1).EntireColumn.Hidden = True
End With
End Sub
'<<=============


---
Regards,
Norman


"Gwen" wrote in message
.. .
Hello,

I need to have a macro that hides all the rows and colums that is not part
of a print area on a sheet.

My print area has graphs, and I tried to hide the rows or columns that
contain the datas, and the graphs disappear.
Is there a solution for this?

Thanks.





All times are GMT +1. The time now is 06:08 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com