ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Zoom to fit Columns (https://www.excelbanter.com/excel-programming/399637-zoom-fit-columns.html)

Sisilla[_2_]

Zoom to fit Columns
 
Hello All,

I want to set Zoom so that all columns can fit in one page. First, I
sum the widths of the visible columns on the page between A and O and
convert the measurement to inches. I then set the Orientation,
PaperSize and Zoom based on the measurement. I am using the following
code-:

Dim cw As Double

Dim Counter As Long
For Counter = 1 To 15
If
Sheets("Application").Columns(Counter).EntireColum n.Hidden = False
Then
cw = cw + Sheets("Application").Columns(Counter).Width
End If
Next Counter

cw = cw / 72

If cw 0 And cw <= 8 Then
Sheets("Application").PageSetup.Orientation = xlPortrait
Sheets("Application").PageSetup.PaperSize = xlPaperLetter
Sheets("Application").PageSetup.Zoom =
WorksheetFunction.RoundDown(700 / cw, 0)
Else
If cw 8 And cw <= 11 Then
Sheets("Application").PageSetup.Orientation =
xlLandscape
Sheets("Application").PageSetup.PaperSize =
xlPaperLetter
Sheets("Application").PageSetup.Zoom =
WorksheetFunction.RoundDown(1000 / cw, 0)
Else
If cw 11 Then
Sheets("Application").PageSetup.Orientation =
xlLandscape
Sheets("Application").PageSetup.PaperSize =
xlPaperLegal
Sheets("Application").PageSetup.Zoom =
WorksheetFunction.RoundDown(1300 / cw, 0)
End If
End If
End If

If my calculations are correct, this code should work fine, but I have
been encountering problems. When cw = 14.76 inches, for example, the
zoom is 88%, but this zoom results in the last column being printed in
a spearate sheet. Theoretically, this Zoom should work since 88% of
14.76 is 13, so all the columns should fit fine on a legal-sized,
landscape-oriented page, but maybe I am not understanding clearly how
Zoom works.

I should note that the left and right margins have been set to zero.
What am I doing wrong here? I appreciate any effort to help me. Thank
you for your time and consideration.

Sincerely,

Sisilla


JE McGimpsey

Zoom to fit Columns
 
Can you not choose File/Page Setup/Page, click the Fit to: radio button
and enter 1 in the "column wide" input box?

Programmatically, that's

With Sheets("Application").PageSetup
.Orientation = Iif(cw <= 8, xlPortrait, xlLandscape)
.PaperSize = Iif(cw <= 11, xlPaperLetter, xlPaperLegal)
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = False
End With



In article . com,
Sisilla wrote:

I want to set Zoom so that all columns can fit in one page.


Sisilla[_2_]

Zoom to fit Columns
 
On Oct 19, 11:18 am, JE McGimpsey wrote:
Can you not choose File/Page Setup/Page, click the Fit to: radio button
and enter 1 in the "column wide" input box?

Programmatically, that's

With Sheets("Application").PageSetup
.Orientation = Iif(cw <= 8, xlPortrait, xlLandscape)
.PaperSize = Iif(cw <= 11, xlPaperLetter, xlPaperLegal)
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = False
End With

In article . com,



Sisilla wrote:
I want to set Zoom so that all columns can fit in one page.- Hide quoted text -


- Show quoted text -


ROTFLMAO

Are you kidding me, JE? Is it really that simple? I can't believe it!
I am blushing over here thinking of how stupid I am. Thanks for the
tip! I greatly appreciate it. -Sisilla


Sisilla[_2_]

Zoom to fit Columns
 
That's cool, CLR. I'm glad to hear that my code wasn't completely
useless! :-)

Cheers,

Sisilla



All times are GMT +1. The time now is 08:49 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com