Variable printarea problem

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Post your macro code here ... not all of us can access such links at work, due to security settings.
 
Upvote 0
How can I set this for multiple pages? It works now only for one page on the sheet it must be two pages

Dim Rng As String
Dim wks As Worksheet
Dim sh As Worksheet
Dim Arr() As String
Dim N As Integer
Dim ws As Worksheet

For Each sh In ActiveWorkbook.Worksheets
If sh.Visible = True And sh.Range("M1").Value = "ja" Then
With sh.PageSetup
On Error Resume Next
lnglastrow = 10
lnglastrow = Application.Evaluate("=MAX(IF(A1:N299<>"""",ROW(A1:N299),10))") 'laatst gebruikte rij voor kolommen A tot N en kijken tot rij 1000
On Error GoTo 0
.PrintArea = "$A$2:$N$" & lnglastrow
.FitToPagesWide = 1
.FitToPagesTall = 1
'sh.PrintPreview
End With
End If
Next
N = 0
For Each sh In ActiveWorkbook.Worksheets
If sh.Visible = xlSheetVisible And sh.Range("M1").Value = "ja" Then
N = N + 1
ReDim Preserve Arr(1 To N)
Arr(N) = sh.Name
End If
Next
If N = 0 Then MsgBox "niets te printen": Exit Sub
With ActiveWorkbook
.Worksheets(Arr).PrintPreview
End With
End Sub
 
Upvote 0
Are you saying that you don't want your print out to be 1 page tall?
 
Upvote 0
No I have 2 print area's but they are variable. I have to set the printarea of the 2 pages dynamic
 
Upvote 0
then the printarea should be set like this:
Code:
PrintArea = "$AF$2:$AU$" & lnglastrow & ",$AW$2:$BG$" & lnglastrow
 
Upvote 0
lnglastrow isn't the same for both pages. I need two times the lnglastrow function in it
 
Upvote 0
And you don't know how to do that? Is that the case? From your macro I'd have thought that you did know how to do that ..... or am I misunderstanding something?
 
Upvote 0

Forum statistics

Threads
1,224,561
Messages
6,179,522
Members
452,923
Latest member
JackiG

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