LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 399
Default Driving me nuts! Row Height, Cell Width

I want to put a border around the range of cells that will print. I figured
if I know how wide my page is between the margins side to side and top to
bottom, I can simply add the widths of all the columns across and rows down
until I hit my page space limits, find the cells that fit that range and set
a border.

Unfortunately, I keep getting 'way off! The following code should (I
thought!!) get me to the bottom right cell that would show on a page.
According to my Print Preview, that's T66. According to my code, though,
it's Q51! What am I not considering?

Ed

Sub CheckRngSize()

Dim rng As Range
Dim endCol As Long
Dim endRow As Long
Dim numTall As Long
Dim numWide As Long
Dim howTall As Long
Dim howWide As Long

endCol = 1
howWide = 0
endRow = 1
howTall = 0

With ActiveSheet.PageSetup
If .Orientation = xlLandscape Then
numTall = Application.InchesToPoints(8)
numWide = Application.InchesToPoints(11)
Else:
numTall = Application.InchesToPoints(11)
numWide = Application.InchesToPoints(8)
End If
End With

Do
howWide = howWide + ActiveSheet.Columns(endCol).Width
endCol = endCol + 1
Loop Until howWide numWide
endCol = endCol - 1

Do
howTall = howTall + ActiveSheet.Rows(endRow).Height
endRow = endRow + 1
Loop Until howTall numTall
endRow = endRow - 1

ActiveSheet.Cells(endRow, endCol).Select

End Sub


 
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
XL2003: "Auto row height" with Wrap Text driving me nuts sebt Excel Discussion (Misc queries) 0 May 1st 07 03:50 PM
Need Help, this is driving me nuts heitorfjr Excel Discussion (Misc queries) 2 January 15th 06 03:10 PM
question driving me nuts Esaam Excel Discussion (Misc queries) 3 December 1st 05 06:03 PM
Driving me nuts. Need more nested than 7 Stressed Excel Discussion (Misc queries) 5 April 12th 05 06:20 PM
Excel / VB is driving me nuts!! Andrew Excel Worksheet Functions 2 November 29th 04 04:06 AM


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

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

About Us

"It's about Microsoft Excel"