Resolve print area into final col and final row

nvalenski

New Member
Joined
Apr 22, 2010
Messages
1
I need to find the final column and final row numbers for a dynamic print area from worksheets in different workbooks so that I may properly define the limits for my For Next loops. The usual method of using Cells(Rows.count,1).End(xlUp).Row or Cells(1,columns.count).End(xlToLeft).Column will not work every time as some cells around the perimeter of some print areas contain text or worksheet calculations. The data I need is always contained within this print area. As a word of caution, sometimes there are empty rows within the print area but no empty columns. Additionally, the last row and last column in the print area always contain data.

As an example, using Activesheet.PageSetup.PrintArea for one spreadsheet I get a print area of $B$1:$M$103. Another print area may be $A$3:$K$80.

Using the first example print area, how can I dynamically set the final column to column M and final row to row 103?

Any help is greatly appreciated!
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
This example assumes that there are no blanks in column "A". Modify as necessary

Sub Macro1()
LastRow = Range("A2").End(xlDown).Row
LastColumn -Range("A2").End(xlToRight).column
ActiveSheet.PageSetup.PrintArea = "$A$1:" & LastColumn & LastRow
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,422
Messages
6,124,811
Members
449,191
Latest member
rscraig11

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