Defining Print_Area based on last row with a value, not just formatting.

NewOrderFac33

Well-known Member
Joined
Sep 26, 2011
Messages
1,275
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
Good afternoon,

I have a worksheet that will contain data between columns A and AG

Data will only be found in alternate columns B,D,F to AF etc) e.g there might by 5 entries in B, 2 in D, 8 in E and so on.

I want the Print_Area of the worksheet to extend to column AG and as far down as the last value in any of these columns.

I can't use CurrentRegion as each of the columns containing data are separated by blank columns C, E, G through to AE

A further complication is that I only want to extend downwards to the last row that that contain a VALUE in any of these columns, not cells that are merely formatted - I started to use the following:
Code:
Dim LastRow As Long
    Dim LastColumn As Long
    
    With ActiveSheet.UsedRange
        LastRow = .Rows(.Rows.Count).Row
        LastColumn = .Columns(.Columns.Count).Column
    End With
    MsgBox ("Last Row: " & LastRow & Chr(10) & "Last Column: " & LastColumn)
    Range("A1").Offset(0, 0).Resize(LastRow, LastColumn).Name = "Print_Area"

My last value was in row 32, but rows 33-35 had a fill colour and LastRow returned 35, not 32.

I don't want to delete the blank columns for presentation purposes.

Can anyone suggest how this could be achieved, please?

Regards

Pete
 
Last edited:

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
This will find the last row with formulas in it even if the formulas are returning "".
Rich (BB code):
LastRow=.Find(What:="*", LookIn:=xlFormulas, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

If you change the argument in red to xlValues it will find the last row with a value in it. Find the last column analogs by changing the searchorder argument to xlByColumns.
 
Upvote 0
It's 21.45 here and my workbook is at work (where it belongs!), so I'm just logging in to say thank you for your solution - I'll give it a try tomorrow! Pete
 
Upvote 0
This worked a treat - thank you very much, and apologies for the late reply!
 
Upvote 0

Forum statistics

Threads
1,215,746
Messages
6,126,643
Members
449,325
Latest member
Hardey6ix

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