Copy 5 rows from one sheet and paste in another sheets based and save as PDF based on condition

Jyotirmaya

Board Regular
Joined
Dec 2, 2015
Messages
205
Office Version
  1. 2019
Platform
  1. Windows
I have data in Sheet1 in Column A & B, I want 5 Rows from Sheet 1 to copy into Sheet 2.

For example I want the data from Sheet 1 A1:A5 to copy into Sheet 2 A8 to A12 and B1:B6 to copy into C8 to C12 of Sheet 2 and save the page as PDF in desktop then continue the process till last row of Sheet1, 5 rows of Sheet 1 to be pasted by replacing existing data and save as PDF then again next 5 rows & so on...I have data till 1500 in Sheet 1 so it should save as PDF for 300 times after copying the data, The saveas PDF file name may be saved as 1,2,3,etc

Book1
AB
1AppleOrange
2CarBus
3RedGreen
4SkyStar
5TigerLion
612
734
856
978
10910
11A B
12C D
13EF
14GH
15IJ
16AppleOrange
17CarBus
18RedGreen
19SkyStar
20TigerLion
211112
221314
231516
241718
251920
26A B
27C D
28EF
29GH
30IJ
Sheet1


Book1
ABC
1Abc
2
3
4
5
6
7
8d
9
10
11
12
Sheet2


Please help me a excel Macro code for that.

Book1
ABC
1Abc
2
3
4
5
6
7
8AppledOrange
9CarBus
10RedGreen
11SkyStar
12TigerLion
Sheet2
Cell Formulas
RangeFormula
A8:A12A8=Sheet1!A1
C8:C12C8=Sheet1!B1
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Try this macro:

VBA Code:
Public Sub Create_PDFs()

    Dim DesktopFolder As String
    Dim r As Long
    
    DesktopFolder = CreateObject("WScript.Shell").SpecialFolders("Desktop") & "\"
    
    With Worksheets("Sheet1")
        For r = 1 To .Cells(.Rows.Count, "A").End(xlUp).Row Step 5
            .Cells(r, "A").Resize(5).Copy Worksheets("Sheet2").Range("A8:A12")
            .Cells(r, "B").Resize(5).Copy Worksheets("Sheet2").Range("C8:C12")
            Worksheets("Sheet2").ExportAsFixedFormat Type:=xlTypePDF, Filename:=DesktopFolder & (r + 5) \ 5 & ".pdf", _
                Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
        Next
    End With
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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