How to define last row from a given starting point

wrmcmahan12

New Member
Joined
May 13, 2015
Messages
12
I'm trying to set print area based on how many rows in a range are not blank. I have tried the offset function to dynamically set a range, but Excel keeps converting the dynamic range to a static range. I'd like to have a button to press that says "print" and will set the proper print area in range $g$3:$J$100 ( if the last entry is in row 20 the range would be $G$3:$J$20). I understand how to do the last row vba function, but the issue is there is another data range below row 100 so I need to find the last row above row 101 for example. How could I adjust the vba to look for the last row above row 101 for instance?
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
if there are no blank rows or columns within the region you want to print you could try use CurrentRegion

Code:
Sub currentregionselect()
ActiveCell.CurrentRegion.Select
End Sub
just sub in a cell in your desired print area for range instead of active cell and change select to whatever it is to set print area
 
Upvote 0
setting print area is different to how i thought. i think the code should be
Code:
Worksheets("Sheet1").PageSetup.PrintArea = Range("G3").CurrentRegion.Address
just change Sheet1 to whatever sheet it is
 
Upvote 0
That's for the reply. The only issue with current region is I only need to print to column I, but the data continues to column NX
 
Upvote 0
That's for the reply. The only issue with current region is I only need to print to column I, but the data continues to column NX

You can try

Code:
Worksheets("Sheet1").PageSetup.PrintArea = Intersect(Worksheets("Sheet1").Columns("G:I"), Worksheets("Sheet1").Range("G3").CurrentRegion).Address
 
Upvote 0

Forum statistics

Threads
1,223,889
Messages
6,175,223
Members
452,620
Latest member
dsubash

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