VBA Code question: Define last row in sheet

Excel789

New Member
Joined
Nov 17, 2010
Messages
9
<!-- / icon and title --><!-- message -->I'm attempting to write code that will base the print area for a spreadsheet on certain criteria. I think I'll be able to manage this if I can name the last row in the spreadsheet "Final Row" and make it equal to the result of a formula contained in cell M2 of the spreadsheet.

Any idea of how/whether this can be accomplished?

Thanks very much!
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Hi,

To find the last row in your sheet try:

For Each Cell In [A65536:IV65536]
If Cell.End(xlUp).Row > Count Then
Count = Cell.End(xlUp).Row
End If
Next Cell

MsgBox "" & Count

If you follw this with:

ActiveCell.Offset(1, 0).Select

Selection.Insert Shift:=xlDown
ActiveCell.FormulaR1C1 = "Final Row"

This will mark the next blank row (R1C1) with Final Row.

Hope that thios helps.

Ned.
 
Upvote 0
Hi,

To find the last row in your sheet try:

For Each Cell In [A65536:IV65536]
If Cell.End(xlUp).Row > Count Then
Count = Cell.End(xlUp).Row
End If
Next Cell

MsgBox "" & Count

If you follw this with:

ActiveCell.Offset(1, 0).Select

Selection.Insert Shift:=xlDown
ActiveCell.FormulaR1C1 = "Final Row"

This will mark the next blank row (R1C1) with Final Row.

Hope that thios helps.

Ned.
Hope this helps
 
Upvote 0
Thanks, but this won't work because I have cells in the spreadsheet that contain formulas that I don't want to capture because they evaluate to "". A range of varying size at the top of the spreadsheet is returned, and below that are the blank cells with formulas in them. Cell M2 contains a formula that will always return a number equal to the number of visible rows in the sheet. If I could express that in the VBA Code, I'd be in good shape, I think.
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,808
Members
452,944
Latest member
2558216095

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