Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatically detecting the last cell & printing to that point

Status
Not open for further replies.

princessk1

Programmer
Feb 28, 2002
74
CA
I have an excel spreadsheet that is populated using VBA. At different times, a different number of cells will be filled. Is there any way for the program to automatically detect the last cell so that when you print the sheet, it prints up to the last cell.

Right now I have to choose Page Break Preview from the view menu and drag the line over to include all of the cells.

Thanks in advance.
 
If your data is contiguous enough, you could select a cell within the data and use the following code:
Code:
ActiveCell.CurrentRegion.Select
Selection.PrintOut
This should select all the data surrounding the active cell, then print the selection only. Note that CurrentRegion stops at blank cells in the same row or column as the active cell.

Good luck...SteveB.
 
Hi - try this


lCol = activesheet.usedrange.columns.count
lRow = activesheet.usedrange.rows.count
with activesheet
.printarea = .usedrange
end with
HTH
~Geoff~
[noevil]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top