Post data from table in a loop into a set cell in a separate sheet

Auslove

New Member
Joined
Aug 17, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I am a novice at VBA and creating macros. Please excuse my ignorance.

I am looking for some help to create a MACRO to copy paste data from a table in one sheet into specific cells in a separate sheet. It will need to be in a loop. The idea is to create automatic PDFs (I've found help for this) from a data table. Each row in the table has unique data, which will be needed to be pasted into a separate sheet onto a dynamic / fixed cell. Copy pasting the first row into the specific cell, then clearing the cell after creating a PDF, then moving to the new row, then repeating the process until the end of the table.

Thank you,
AusLove
 

Attachments

  • 123.png
    123.png
    17.2 KB · Views: 15

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Try this macro. It assumes the data is in columns A:C in a sheet named "Data" and the payslip sheet is named "Payslip". Copies cells A:C to B3, B6, B9 on "Payslip". The .pdf files are named after the A and B cells and saved in the same folder as the workbook.
VBA Code:
Public Sub Create_PDFs()

    Dim saveInFolder As String
    Dim payslipSheet As Worksheet
    Dim lastRow As Long, r As Long
   
    saveInFolder = ThisWorkbook.Path & "\"
    If Right(saveInFolder, 1) <> "\" Then saveInFolder = saveInFolder & "\"
   
    Set payslipSheet = Worksheets("Payslip")
   
    With Worksheets("Data")
        lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
        For r = 2 To lastRow
            .Cells(r, "A").Copy payslipSheet.Range("B3")
            .Cells(r, "B").Copy payslipSheet.Range("B6")
            .Cells(r, "C").Copy payslipSheet.Range("B9")
            payslipSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=saveInFolder & .Cells(r, "A").Value & " " & .Cells(r, "B").Value & ".pdf", Quality:=xlQualityStandard
        Next
    End With
   
    MsgBox "Done"
   
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,791
Messages
6,121,611
Members
449,038
Latest member
apwr

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