Save workbook multiple times as PDF with different names from range and an auto fill feature

sgilmoreBBP

New Member
Joined
Oct 4, 2022
Messages
3
Office Version
  1. 365
Platform
  1. Windows
HI all.

I'm a complete novice when it comes to VBA and Macros. I'm really hoping a whiz can save me a lot of time. I want to increase prices on a master price list but require two automated tasks in order to make my task significantly easier.
My workbook has 3 sheets.

Sheet 1 (Account Name)
has a list of customers in column A with a header in cell A1.

Sheet 2 (Current Price List)
Has the current price list with an additional column where I can input the amount that the current price will increase by (not by a percentage)

Sheet 3 (2023 Price List)
This sheet is the same as sheet 2 the only difference is that I have removed the additional column. I use a basic 'SUM' formula to now show the newly increased price.


What I'd like to achieve.
I'd like to save sheet 3 around 50 times (could be more could be less) as a PDF always in the same pre set folder, each save will have a new save name which it will pick up from the list of customers in column A in sheet 1.

Further to this, on Sheet 3 I have a cell where before I save the file to a PDF would it be possible to automatically insert the same customer name that will be used as the save name? the cell reference for this is "G3"
An example:
'customer 1' (pulled from sheet 1 cell A2) will be inserted into cell G3 on sheet 3 and then the file will be saved as PDF as "customer 1".
'customer 2' (pulled from sheet 1 cell A3) will be inserted into cell G3 on sheet 3 and then the file will be saved as PDF as "customer 2".
'customer 3' (pulled from sheet 1 cell A4) will be inserted into cell G3 on sheet 3 and then the file will be saved as PDF as "customer 3".

and so on.......




Sheet 1 (Account Name)
Book3
A
1Account Name
2Customer 1
3Customer 2
4Customer 3
5Customer 4
6Customer 5
7Customer 6
8Customer 7
9Customer 8
10Customer 9
11Customer 10
12Customer 11
13Customer 12
14Customer 13
15Customer 14
16Customer 15
17Customer 16
18Customer 17
19Customer 18
20Customer 19
Account Name



Sheet 3 (2023 Price List)
Book3
ABCDEFGHIJ
1
2
3Customer:-
4Date:- 03/10/2022
5Validity:-3 months from date of quote
6
7
8
9Product DescriptionBBP Product CodeShelf life upon manufacture (months unless stated otherwise)Case SizeCases per LayerLayers per PalletCases per PalletPrice per unitPrice per case
10Case Weight
11(£)(£)
12Fresh Product 1FR121 days2 x (6 x 190g)2.28kg189162£3.80£7.60
13Fresh Product 2FR21560 x 40g2.4kg2010200£4.95£4.80
14Fresh Product 3FR31560 x 57g3.42kg1412168£6.15£6.10
15Fresh Product 4FR4610 x 1.36kg13.60kg(19 x 3) + 33+3 on top60£2.20£22.00
16Fresh Product 5FR5610 x 1.36kg 13.60kg (19 x 3) + 33+3 on top60£2.30£23.00
17Fresh Product 6FR6610 x 1.36kg13.60kg(19 x 3) + 33+3 on top60£3.05£30.50
18Fresh Product 7FR7610 x 1.36kg13.60kg(19 x 3) + 33+3 on top60£3.40£34.00
19Fresh Product 8FR8612 x 454g5.448kg(29 x 5) + 165+16 on top161£0.95£11.40
20Fresh Product 9FR9612 x 334g4.008kg189162£1.75£21.00
21Fresh Product 10FR10612 x 220g2.64kg455225£0.77£9.24
22Fresh Product 11FR11612 x 220g2.64kg455225£1.31£15.72
23Fresh Product 12FR12612 x 220g2.64kg455225£0.82£9.84
24Fresh Product 13FR13612 x 220g2.64kg455225£0.89£10.68
25Fresh Product 14FR14612 x 220g2.64kg455225£0.97£11.64
2023 Price List
Cell Formulas
RangeFormula
H12H12=F12*G12
J12J12=I12*2
I12:I25I12=SUM('[Book1]2022 Price list'!I12+'[Book1]2022 Price list'!J12)
J15:J18J15=I15*10
J19:J25J19=I19*12
G20:G25G20=H20/F20
 

Attachments

  • Sheet 3.png
    Sheet 3.png
    72.3 KB · Views: 11
  • Sheet 1.png
    Sheet 1.png
    11.9 KB · Views: 21

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Update.
I've watched a few videos on you tube and have put together the following module. But I'm getting the error for line "Customer = AccountName.Cells(i, l).Text
"Run-time error '424':

Object Required


This is where my lack of skill set lets me down.

Sub Save_as_PDF()

Dim data As Worksheet
Dim list As Worksheet
Dim Customer As String
Dim count As Long
Dim i As Long


Set data = ThisWorkbook.Sheets(3)
Set list = ThisWorkbook.Sheets(1)

'count number of customers
list.Activate
count = WorksheetFunction.CountA(Range("A1", Range("A1").End(xlDown)))

data.Activate

For i = 1 To count

'Updating Customer Name
Customer = AccountName.Cells(i, 1).Text
2023 PriceList.Cells(3, 7) = Customer

'Save PDF'
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:="S:\Temp\PDF save test\" & _
"Food Services - " & Customer

Next i

ActiveSheet.AutoFilterMode = False

End Sub[/CODE][/CODE]
 
Upvote 0
Try:
VBA Code:
Sub CopySheetPDF()
    Application.ScreenUpdating = False
    Dim custWS As Worksheet, cust As Range
    Set custWS = Sheets("Sheet1")
    With custWS
        For Each cust In .Range("A2", .Range("A" & .Rows.Count).End(xlUp))
            Sheets("Sheet3").Copy
            With ActiveSheet
                .Range("G3") = cust
                .ExportAsFixedFormat Type:=xlTypePDF, Filename:="S:\Temp\PDF save test\" & "Food Services - " & cust
            End With
        Next cust
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hey @mumps Thank you for replying. I sorted it in the end after lots of googling. In the end this is what I used:

Sub Save_as_PDF()

Dim data As Worksheet
Dim list As Worksheet
Dim Customer As String
Dim count As Long
Dim i As Long


Set data = ThisWorkbook.Sheets(3)
Set list = ThisWorkbook.Sheets(1)

'count number of customers
list.Activate
count = WorksheetFunction.CountA(Range("A1", Range("A1").End(xlDown)))

data.Activate

For i = 1 To count

'Updating Customer Name
Customer = Worksheets("AccountName").Cells(i, 1)
Worksheets("NewPriceList").Cells(3, 7) = Customer

'Save PDF'
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:="S:\Temp\PDF save test\" & _
"Food Services - " & Customer

Next i

ActiveSheet.AutoFilterMode = False

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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