Dynamic Print Range

bgonen

Active Member
Joined
Oct 24, 2009
Messages
264
I am trying to:

First, make column A as the column to repeat (page setup,,)

Second; Highlight the range A1 to the last used cell (the row should be 59)

Third; add page breaks every 15 columns

Fourth; Print preview
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
As a start
I am trying to use my dynamic range as below:(But of course I get error/s)

Sub PrintPreview()

Dim LC As Long
With Sheets("TMHP-PL")
LC = .Cells(A1, Columns.Count).End(xlToLeft).Column
.PrintArea = Range("a1" & LC).SpecialCells(xlCellTypeVisible).Address
End With
End Sub
 
Upvote 0
Maybe like this (and please stop sending me PMs when I am trying to answer your questions!)

Code:
Sub PrintPreview()

Dim LC As Long
With Sheets("TMHP-PL")
    LC = .Cells(1, Columns.Count).End(xlToLeft).Column
    PageSetup.PrintArea = .Range(.Cells(1, 1), .Cells(59, LC)).SpecialCells(xlCellTypeVisible).Address
End With
End Sub
 
Upvote 0
Missed a dot

Rich (BB code):
Sub PrintPreview()

Dim LC As Long
With Sheets("TMHP-PL")
    LC = .Cells(1, Columns.Count).End(xlToLeft).Column
    .PageSetup.PrintArea = .Range(.Cells(1, 1), .Cells(59, LC)).SpecialCells(xlCellTypeVisible).Address
End With
End Sub
 
Upvote 0
Here is a fix for your last post. I'm not sure how this fits in with your first request, but this sets the print area to the used columns. Also, you should refrain from naming a sub PrintPreview, I think it is a reserved word.

Code:
Sub PPV()
    Dim LC As String
    With Sheets("TMHP-PL")
        LC = Left(.Cells(1, .Cells(1, .Columns.Count).End(xlToLeft).Column).Address(1, 0), _
            InStr(1, .Cells(1, Cells(1, .Columns.Count).End(xlToLeft).Column).Address(1, 0), "$") - 1)
        .PrintArea = .Range("A:" & LC).SpecialCells(xlCellTypeVisible).Address
    End With
End Sub
 
Upvote 0
That's a progress thanks a lot

Now, what if I want to fit to multiple ranges/pages;

For example Cell A1:O59 will be the first page

Then P1:AC59 will be the second page
(I am trying to make column A as the column to repeat)

In other words, Column A will repeat on the left and then the following 14 columns together will compose a page,,

Also, I try to Landscape each page
 
Upvote 0
This will repeat column A on every page. If you have your column widths set so that only 16 columns will fit on a page then you should get the desired results.

Code:
    With Sheets("TMHP-PL")
        .PageSetup.PrintTitleColumns = "$A:$A"
    End With
 
Upvote 0
Not sure on 2007. I usually just play with the widths until the page break shows up in the right spot. BTW, I use 2003.
 
Upvote 0

Forum statistics

Threads
1,224,507
Messages
6,179,176
Members
452,893
Latest member
denay

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top