Last data rng on sheet, ignoring blank cells

TTom

Well-known Member
Joined
Jan 19, 2005
Messages
518
I know how to set a range A1 to last cell data row & column if there are no blank cells, but how do I find the last
cell range (row, column) if there are blank cells, rows, and/or columns, before the lowest, right most cell with data?

Only works until hits a blank cell in column A or blank cell in row 1?
<code>
Set rng1 = Range(Cells(1, 1), Cells(Range("A65000").End(xlUp).Row, Range("IV1").End(xlToLeft).Column))
</code>
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Code:
With ActiveSheet
    Set rng1 = Range(.Range("A1"),.UsedRange)
End With

This range is the smallest range that holds cell A1 and all the data.
If F9 and E10 hold data, but F10 does not (and no other cell to the right or down), F10 will be in that range.
If the bottom right cell holds a formula that returns "", it will be in that range.
 
Last edited:
Upvote 0
UsedRange referrs to not only data area, also any cells with changed format.
try
Rich (BB code):
Sub test()
Dim LastR As Long, LastC As Long
 With ActiveSheet
    LastR = .Cells.Find("*", , , , xlByRows, xlPrevious).Row
    LastC = .Cells.Find("*", , , , xlByColumns, xlPrevious).Column
    .Cells(1).Resize(LastR, LastC).Select
 End With
End Sub
 
Upvote 0
First code works to include formated cells such as boarders but no data,
2nd code just goes to last data and ignores formatting.
Both will be useful and I'll put into my notebook, study and learn.
Thanks guys!
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,742
Members
448,989
Latest member
mariah3

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