PDF creation of different sheet based on column value.

mummbles74

Board Regular
Joined
Nov 14, 2009
Messages
120
Office Version
  1. 365
Platform
  1. Windows
Ok something I haven't attempted before.

I have a spread sheet that has sheet containing all of the information for different electrical loops. (sheet name "DATA")
I started with a signal template on a separate sheet ("Cable Schematic") and I use other formulas directly in the cells on that sheet to 'transfer' over the information from the DATA sheet based on the tag number selected in a certain cell (AC1)
The code below cycles through each row on the DATA sheet, on the CABLE SCHEMATIC template and creates a PDF for each row.

Row = 2
Do Until IsEmpty(Worksheets("Data").Cells(Row, 1))
Sheets("Cable schematic").Range("AC1") = Worksheets("Data").Cells(Row, 1)
Sheets("Cable schematic").ExportAsFixedFormat Type:=xlTypePDF, Filename:=ThisWorkbook.Path & "\" & Worksheets("Data").Cells(Row, 7) & "-" & Worksheets("Data").Cells(Row, 1)
Row = Row + 1
Loop

the above code seem to work perfectly, puts the created PDF's in the same folder as the excel sheet and does exactly what is required.

I now have several other templates across other sheets that are different templates that reflect the different designs of circuits. On the DATA tab, column BN states what template to use. The different templates are called the following:
Cable schematic
Cable + JB schematic
Cable + Plug schematic
Cable + Plug No Probe

What I would like to do is still cycle through the ROWs on the DATA tab but this time based on the value in BN select a different template type. I assumed that it would be a case of running the above code several times basing it on the value in BN but I can not see any other examples that explain how to do this.

Any help would be greatly appreciated.
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Try this macro:
VBA Code:
Public Sub Create_PDFs()

    Dim Row As Long
    
    Row = 2
    With Worksheets("Data")
        Do Until IsEmpty(.Cells(Row, "A").Value)
            Worksheets(.Cells(Row, "BN").Value).Range("AC1") = .Cells(Row, "A").Value
            Worksheets(.Cells(Row, "BN").Value).ExportAsFixedFormat Type:=xlTypePDF, Filename:=ThisWorkbook.Path & "\" & .Cells(Row, "G").Value & "-" & .Cells(Row, "A").Value
            Row = Row + 1
        Loop
    End With
    
    MsgBox "Done"
    
End Sub
 
Upvote 0
Solution
Try this macro:
VBA Code:
Public Sub Create_PDFs()

    Dim Row As Long
  
    Row = 2
    With Worksheets("Data")
        Do Until IsEmpty(.Cells(Row, "A").Value)
            Worksheets(.Cells(Row, "BN").Value).Range("AC1") = .Cells(Row, "A").Value
            Worksheets(.Cells(Row, "BN").Value).ExportAsFixedFormat Type:=xlTypePDF, Filename:=ThisWorkbook.Path & "\" & .Cells(Row, "G").Value & "-" & .Cells(Row, "A").Value
            Row = Row + 1
        Loop
    End With
  
    MsgBox "Done"
  
End Sub
That is amazing thank you.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,711
Messages
6,174,020
Members
452,542
Latest member
Bricklin

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