two printing areas

PIsabel

Board Regular
Joined
Feb 4, 2014
Messages
121
Office Version
  1. 365
Platform
  1. Windows
I have a sheet where lines of data are pasted.
I can have a sheet with 1 , 10 or 100 lines
Then I insert formulas that summarize the information entered there to create a summary report.
I need a code that selects the print area of the two sets inserted but I need it to always be done on separate sheets.
I know that after the last line of data pasted I have an offset of 10 lines and the report lines are inserted on the 11th line and contain 15 lines.
Basically there are two printing areas that will always be printed on different sheets.
The only thing I managed to do was create a code that selected the first impression and do it separately, I didn't want to

VBA Code:
Sub printteste()

    Dim LastRow1 As Long

    With ActiveSheet
    LastRow1 = .Cells(.Rows.Count, "F").End(xlUp).Offset(-10).Row
    .PageSetup.PrintArea = "C6:J" & LastRow1
    End With

End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
VBA Code:
 With ActiveSheet
    .PageSetup.PrintArea = "C6:J20,C25:J30" '2 ranges for your printarea (adapt to your situation)
    End With
 
Upvote 0
It doesn't work because the report is inserted at the end of a line, 10 or 100, it never has a fixed cell
 
Upvote 0
with adapting to your situation, i meant
VBA Code:
Sub printteste()
     Dim LastRow1 As Long

     With ActiveSheet
          LastRow1 = .Cells(.Rows.Count, "F").End(xlUp).Offset(-10).Row
          Set c1 = Range("C6:J" & LastRow1)                     'your 1st range
          Set c2 = c1.Offset(c1.Rows.Count + 11).Resize(15)     '2nd range is with a gap of 10 rows under the 1st and 15 rows
          .PageSetup.PrintArea = Union(c1, c2).Address
     End With

End Sub
 
Upvote 0
Solution
Thank you very much.
works impeccably well

Obrigado = Thanks
with adapting to your situation, i meant
VBA Code:
Sub printteste()
     Dim LastRow1 As Long

     With ActiveSheet
          LastRow1 = .Cells(.Rows.Count, "F").End(xlUp).Offset(-10).Row
          Set c1 = Range("C6:J" & LastRow1)                     'your 1st range
          Set c2 = c1.Offset(c1.Rows.Count + 11).Resize(15)     '2nd range is with a gap of 10 rows under the 1st and 15 rows
          .PageSetup.PrintArea = Union(c1, c2).Address
     End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,044
Messages
6,122,827
Members
449,096
Latest member
Erald

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