Vba to loop copy and past one cell at a time until blank

sjramos

New Member
Joined
Jul 24, 2016
Messages
2
Hi all,
I am confident you can help a novice like me. I want to copy one cell at a time from sheet2 (cell x2 until blank) and paste in sheet1(cell j3). I want to loop it with my code for printing pdf. So, when the cell is copied and pasted as values it will do the calculations and print pdf. Then copy n paste the next cell, Until it finds a blank cell and stops.

Thank you,
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Which column have values in sheet2?
Assuming ColumnA in sheet2 has values, please try this code.

Code:
Sub pdf()
Dim cnt As Long, LastR As Long
Dim ws1 As Worksheet, ws2 As Worksheet, w
Const path = "C:\Users\User\Desktop\"
Set ws1 = Sheets("Sheet1")
Set ws2 = Sheets("Sheet2")

cnt = 1
With ws2
    For Each w In .Range(.Range("A2"), .Range("A2").End(xlDown))
        ws1.Range("J3").Value = w.Value
        ws1.ExportAsFixedFormat Type:=xlTypePDF, _
        Filename:=path & cnt & "_" & Format(Date, "ddmm") & ".pdf", _
        Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, _
        IgnorePrintAreas:=False, _
        OpenAfterPublish:=False
        cnt = cnt + 1
    Next
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

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