Cells.SpecialCells(xlCellTypeLastCell).Row Question

Wee Kuang

Board Regular
Joined
Sep 15, 2011
Messages
59
Dear all,

I'm currently devising this code to do a automatic setting of print area. The statement goes like this.

LastRow = Cells.SpecialCells(xlCellTypeLastCell).Row
ActiveSheet.PageSetup.PrintArea = "$A$1:$X$" & LastRow + 3

I thought it was alright but when I run the code and check the print area. I had like 7 more pages without any data inside these pages. Can anyone point to me if my code is correct?

Any help will more warmly welcome. :laugh:
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
I believe SpecialCells uses the UsedRange, which can falsely report. In your code, tack in:
Code:
MsgBox Cells.SpecialCells(xlCellTypeLastCell).Address

Does it tell you an address that you expect, or way off down the sheet?
 
Last edited:
Upvote 0
Hi GTO. Thanks for this little trick.:) It showed me X1050 which was totally off. Haha. The last cell should be X150 though.

The active sheet, that the code is working on for the print area, has its data content obtained from filtering, copy and paste(visible cells only) of another Masterlist.

Could this be the problem? Thanks for your help once again.
 
Upvote 0
If I am understanding correctly, you are saying that you copy from a filtered list, and paste onto the sheet we're printing, right?

It shouldn't interfere, but try something easy. Whichever column can be counted on to have data in each row, select a cell. With the CTRL key pressed, press the down arrow key until it jumps to the end of the sheet (downward). Then press the up arrow once (CTRL is still depressed). Does that get you to the last row of visble data?
 
Upvote 0
Hello. I tried what you suggested and it got me back to the last row of data which is row 150.
 
Upvote 0
Okay, try:
Code:
ActiveSheet.PageSetup.PrintArea = "$A$1:$X$" & Cells(Rows.Count, "A").End(xlUp).Row + 3
I am guessing that column A is dependable to find the last row of data...
 
Upvote 0
Hello. I tried what you suggested and it got me back to the last row of data which is row 150.
 
Upvote 0
You are most welcome and thank you for letting me know it worked :-)
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,947
Latest member
Gerry_F

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