Excel

TheSmallman.com

an XL ideas Lab

Dashboards VBA
  • Home
  • Dashboards
    • Tips & Tricks
    • Charts
    • Modelling
    • Infographics
    • VBA
  • Shop Dashboards
    • Power Pivot a User Guide
    • Excel Dashboard Course
    • Advanced Dashboard Course
    • Financial Modelling Course
    • Excel VBA Course
  • Blog
  • About
Menu

Excel Dashboards VBA

Street Address
City, State, Zip
Phone Number
an XL ideas Lab

Your Custom Text Here

Excel Dashboards VBA

  • Home
  • Dashboards
  • Excel Tips
    • Tips & Tricks
    • Charts
    • Modelling
    • Infographics
    • VBA
  • Shop Dashboards
  • PowerPivot
    • Power Pivot a User Guide
  • Courses
    • Excel Dashboard Course
    • Advanced Dashboard Course
    • Financial Modelling Course
    • Excel VBA Course
  • Blog
  • About

Excel Change Print Area with VBA

May 12, 2016 Marcus Small

Setting the print area on a moving range can be a difficult and frustrating thing to trap.  You may wish to trap a specific range with your print area or have the print range only consider certain columns.  Let's say you have a couple of helper columns in an Excel workbook and don't want these columns to be printed but you want the columns to be visible.  You could manually set the print area to exclude the print area but now you have more data which you have added and you would like the print area to update in kind. 

The following VBA procedure will generate a print area which considers columns A to D.

Option Explicit

Sub PrintArea()
Dim sh as Worksheet
Set sh = Sheet1

   sh.PageSetup.PrintArea =sh.Range("A1", sh.Range("D65536").End(xlUp)).Address
End Sub

The above will trap the last used range in column D.  Make sure the sheet you are using it on is changed.

Sheet1 is the worksheet code name.  This needs to be adjusted if you are using the code on a sheet other than sheet1. 

Oh this is set up for Excel 2003 so here is an update for Excel 2007 and above. 

Option Explicit

Sub PrintArea1()
Dim sh as Worksheet
Set sh = Sheet1

   sh.PageSetup.PrintArea = sh.Range("A1", sh.Range("D" & rows.count).End(xlUp)).Address
End Sub

Why does it work?  Well the only range which is considered in the print area is from A1 to the last used row in Column D.

What if you wanted it to be the current region.  Perhaps something like the following.

Sub testo1()
   Sheet1.PageSetup.PrintArea = [A1].CurrentRegion.Address
End Sub

Where all of the data in the 'block' of data will be considered part of the print area.  This sort of code could be added to a change event so the macro would not have to be run over and again to make it fire. 

Tags Excel, Print, area, vba, set
← Open Excel Update FileRead Individual Columns to an Array →

Featured Posts

Excel Dashboards: Tracking a Crisis

Excel Dashboards: Tracking a Crisis
April 14, 2020

Recent Posts

Populating an Excel Table from a Range of Cells with VBA

Populating an Excel Table from a Range of Cells with VBA June 12, 2025

Fuzzy Distribution with Randbetween

Fuzzy Distribution with Randbetween May 21, 2025

Add Minimum and Maximum for Chart in Cells

Add Minimum and Maximum for Chart in Cells March 12, 2025

Inflation Over Multiple Years in a Single Cell

Inflation Over Multiple Years in a Single Cell January 10, 2025

Hubspot Dashboard

Hubspot Dashboard October 3, 2024

Monthly Dashboard With Supporting Metrics

Monthly Dashboard With Supporting Metrics September 25, 2024

Excel Show Missing Sheet Tabs

Excel Show Missing Sheet Tabs July 29, 2024

Run Macro Overnight Automatically

Run Macro Overnight Automatically June 24, 2024

Split File into Parts and Save to Directory

Split File into Parts and Save to Directory April 20, 2024

Most Popular Author

Most Popular Author December 14, 2023

 

Follow US:

 
 

MarcusSmall@thesmallman.com

 

TheSmallman.com - Making your small systems hum...
© Copyright 2013-2024 theSmallman.com All Rights Reserved.