VBA macro for REPLACE cell value from a list THEN print in a single PDF Document!

INOpportuno

New Member
Joined
Jul 5, 2023
Messages
6
Office Version
  1. 2021
Platform
  1. Windows
I found in this forum how to printout sheets with different values, but I'd like to print all the sheets in a single PDF Document.
How can I fix this VBA code to do this?

Sub PrintAll()


Dim i As Long, LastRow As Long


LastRow = Worksheets("Names").Range("A65536").End(xlUp).Row


For i = 1 To LastRow
Worksheets("Form").Range("A1").Value = Worksheets("Names").Range("A" & i).Value
Worksheets("Form").Range("Print_Me").PrintOut
Next i


End Sub
 
I'm not good to explain...i attached an immage
 

Attachments

  • List-min.jpg
    List-min.jpg
    167.6 KB · Views: 7
Upvote 0

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
I am sorry but the attachment does not mean anything to me. I can't see any relation between what you posted so far and that picture.
In your post(s) you mention column A but column A is not even visible on your picture.
Sorry, but if you can't give us an explanation, even if it is in broken english, I can't do anything anymore.
 
Upvote 0
Maybe you were thinking about something like this?
Code:
Sub Try_So_Version_2()
Dim a As String, shts, ws As Worksheet, prntNames, i As Long
a = ActiveSheet.Name
prntNames = Sheets("Names").Range("A1:A" & Sheets("Names").Cells(Rows.Count, 1).End(xlUp).Row).Value
Worksheets("Form").PageSetup.PrintArea = Range("Print_Me").Address
Application.ScreenUpdating = False
    For i = LBound(prntNames) To UBound(prntNames)
        With Sheets("Form")
            .Range("A1").Value = prntNames(i, 1)
            Worksheets.Add.Name = prntNames(i, 1)
            .Range("Print_Me").Copy Sheets(prntNames(i, 1)).Cells(1)
        End With
    Next i
    Sheets(prntNames(1, 1)).Select
    For i = 2 To UBound(prntNames)
        Sheets(prntNames(i, 1)).Select False
    Next i
ActiveSheet.ExportAsFixedFormat xlTypePDF, ThisWorkbook.Path & "\" & "INOpportuno At MrExcel" & ".pdf"
Sheets(a).Select
    For i = LBound(prntNames) To UBound(prntNames)
        Application.DisplayAlerts = False
            Sheets(prntNames(i, 1)).Delete
        Application.DisplayAlerts = False
    Next i
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,177
Members
452,615
Latest member
bogeys2birdies

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