Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
tom tom is offline
external usenet poster
 
Posts: 570
Default Code modification help please

Hi all,
I could sure use some help with the following code. I'm using this to set
the print area on a sheet. The problem is, that it is shrinking the selection
WAY too small - not to "fit to page" as I was wanting it to. Any
suggestions???

Thanks,
Tom

Lrow = ActiveSheet.Range("A:O").SpecialCells(xlCellTypeLa stCell).Row
With ActiveSheet.PageSetup
.PrintArea = "$A$1:$O$" & Lrow
.Zoom = False
.LeftMargin = Application.InchesToPoints(0.5)
.RightMargin = Application.InchesToPoints(0.5)
.TopMargin = Application.InchesToPoints(0.5)
.BottomMargin = Application.InchesToPoints(0.5)
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Code modification help please

I suspect that lrow is overstated.

sub SetPrintArea()
Dim Lrow as Long
Lrow = GetRealLastCell(Activesheet).row
With ActiveSheet.PageSetup
.PrintArea = "$A$1:$O$" & Lrow
.Zoom = False
.LeftMargin = Application.InchesToPoints(0.5)
.RightMargin = Application.InchesToPoints(0.5)
.TopMargin = Application.InchesToPoints(0.5)
.BottomMargin = Application.InchesToPoints(0.5)
.FitToPagesWide = 1
.FitToPagesTall = 1
End With

End Sub

Function GetRealLastCell(sh as Worksheet) as Range
Dim RealLastRow As Long
Dim RealLastColumn As Long
On Error Resume Next
RealLastRow = _
sh.Cells.Find("*", sh.[A1], , , xlByRows, xlPrevious).Row
RealLastColumn = _
sh.Cells.Find("*", sh.[A1], , , xlByColumns, xlPrevious).Column
set GetRealLastCell = sh.Cells(RealLastRow, RealLastColumn)
End Function

--
Regards,
Tom Ogilvy


"Tom" wrote:

Hi all,
I could sure use some help with the following code. I'm using this to set
the print area on a sheet. The problem is, that it is shrinking the selection
WAY too small - not to "fit to page" as I was wanting it to. Any
suggestions???

Thanks,
Tom

Lrow = ActiveSheet.Range("A:O").SpecialCells(xlCellTypeLa stCell).Row
With ActiveSheet.PageSetup
.PrintArea = "$A$1:$O$" & Lrow
.Zoom = False
.LeftMargin = Application.InchesToPoints(0.5)
.RightMargin = Application.InchesToPoints(0.5)
.TopMargin = Application.InchesToPoints(0.5)
.BottomMargin = Application.InchesToPoints(0.5)
.FitToPagesWide = 1
.FitToPagesTall = 1
End With

  #3   Report Post  
Posted to microsoft.public.excel.programming
tom tom is offline
external usenet poster
 
Posts: 570
Default Code modification help please

Thanks Tom!

"Tom Ogilvy" wrote:

I suspect that lrow is overstated.

sub SetPrintArea()
Dim Lrow as Long
Lrow = GetRealLastCell(Activesheet).row
With ActiveSheet.PageSetup
.PrintArea = "$A$1:$O$" & Lrow
.Zoom = False
.LeftMargin = Application.InchesToPoints(0.5)
.RightMargin = Application.InchesToPoints(0.5)
.TopMargin = Application.InchesToPoints(0.5)
.BottomMargin = Application.InchesToPoints(0.5)
.FitToPagesWide = 1
.FitToPagesTall = 1
End With

End Sub

Function GetRealLastCell(sh as Worksheet) as Range
Dim RealLastRow As Long
Dim RealLastColumn As Long
On Error Resume Next
RealLastRow = _
sh.Cells.Find("*", sh.[A1], , , xlByRows, xlPrevious).Row
RealLastColumn = _
sh.Cells.Find("*", sh.[A1], , , xlByColumns, xlPrevious).Column
set GetRealLastCell = sh.Cells(RealLastRow, RealLastColumn)
End Function

--
Regards,
Tom Ogilvy


"Tom" wrote:

Hi all,
I could sure use some help with the following code. I'm using this to set
the print area on a sheet. The problem is, that it is shrinking the selection
WAY too small - not to "fit to page" as I was wanting it to. Any
suggestions???

Thanks,
Tom

Lrow = ActiveSheet.Range("A:O").SpecialCells(xlCellTypeLa stCell).Row
With ActiveSheet.PageSetup
.PrintArea = "$A$1:$O$" & Lrow
.Zoom = False
.LeftMargin = Application.InchesToPoints(0.5)
.RightMargin = Application.InchesToPoints(0.5)
.TopMargin = Application.InchesToPoints(0.5)
.BottomMargin = Application.InchesToPoints(0.5)
.FitToPagesWide = 1
.FitToPagesTall = 1
End With

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Code modification help AndyMP Excel Worksheet Functions 1 February 8th 09 11:41 PM
Code modification help please Chris Hankin[_4_] Excel Programming 2 March 26th 07 04:42 AM
Modification in the CODE to HIDE rows and columns that start with ZERO (code given) Thulasiram[_2_] Excel Programming 4 September 26th 06 04:15 AM
modification for the code srinivasan Excel Programming 2 August 20th 05 03:12 PM
Modification to code Peter Atherton Excel Programming 1 September 23rd 03 07:36 PM


All times are GMT +1. The time now is 08:10 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"