Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Lisa Anderson   on Nov 06 In MS Office Category.

  
Question Answered By: Vickie Smith   on Nov 06

I'm not sure, but I think what you're asking is to identify the last
column and then set the print  area accordingly. I understood that
your "last row" is set already at 710, but in case you need to
identify the last row and column  (i.e. the lastcell used on the
spreadsheet), here is one option:

Sub FindLastCell()
Dim LastColumn As Integer
Dim LastRow As Long
Dim LastCell As Range
If WorksheetFunction.CountA(Cells) > 0 Then
'Search for any entry, by searching backwards by Rows.
LastRow = Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
'Search for any entry, by searching backwards by Columns.
LastColumn = Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column
MsgBox Cells(LastRow, LastColumn).Address
End If
End Sub

Then, set the print area with:
Range(Cells(1, 1), Cells(LastRow, LastColumn)).Select
ActiveSheet.PageSetup.PrintArea = Selection.Address

Share: 

 

This Question has 1 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Sort Column Or get search suggestion and latest updates.


Tagged: