Adding a sheet to a "save as" macro

Mr_Phil

Board Regular
Joined
May 28, 2018
Messages
141
Office Version
  1. 365
Hi. I am stumped. I've googled and googled and still haven't hit on the right keyword combination to explain to me what I need to do.
This code takes my template and saves it as a filename based on Q1. It worked fine with minor copy/paste adjustments. But recently I have needed to add a sheet from the original as those items have become more valuable. The sheet name is "inventory calculations".

Basically we open the RSP PO Form Template and want to copy both sheets (Subcontractor PO Form and Inventory Calculations) to the new workbook which is saved as shown below. But, I don't see a clear way to say that in VBA. Any tips or advice is gratefully welcomed. Thank you for looking.

VBA Code:
Sub Export()
    Application.ScreenUpdating = False
    Dim wb As Workbook
    Set wb = ThisWorkbook
    Workbooks.Open FileName:=wb.Path & "\RSP PO Form Template New.xlsx"
    With Workbooks("RSP PO Form Template New.xlsx").Sheets("RSP PO Form")
        If .Range("Q1").Value <> "" Then
            Workbooks("DISH ORDER WORKSHEET.xlsb").Sheets("Subcontractor PO Form").Range("H17:H500").Copy
            .Range("H17").PasteSpecial Paste:=xlPasteValues
            .Copy
                  
            ActiveWorkbook.SaveAs FileName:=wb.Path & "\" & .Range("Q1").Value & ".xlsx", FileFormat:=51
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
I suggest you organize in a table, which book-sheet-range (or maybe the whole sheet) you want to copy and where you want to put it.

1664321046730.png
 
Upvote 0
You did not tell us which range to copy and which range to paste for 2nd copy.
Assume:
VBA Code:
If .Range("Q1").Value <> "" Then
            Workbooks("DISH ORDER WORKSHEET.xlsb").Sheets("Subcontractor PO Form").Range("H17:H500").Copy
            .Range("H17").PasteSpecial Paste:=xlPasteValues
            
            'ADDED PART: second copy: assume copy range("I17:I500") then paste to range "I17")
            Workbooks("DISH ORDER WORKSHEET.xlsb").Sheets("Inventory Calculations").Range("I17:I500").Copy
            .Range("I17").PasteSpecial Paste:=xlPasteValues

                  
            ActiveWorkbook.SaveAs FileName:=wb.Path & "\" & .Range("Q1").Value & ".xlsx", FileFormat:=51
 
Upvote 0
Solution
You did not tell us which range to copy and which range to paste for 2nd copy.
Assume:
VBA Code:
If .Range("Q1").Value <> "" Then
            Workbooks("DISH ORDER WORKSHEET.xlsb").Sheets("Subcontractor PO Form").Range("H17:H500").Copy
            .Range("H17").PasteSpecial Paste:=xlPasteValues
           
            'ADDED PART: second copy: assume copy range("I17:I500") then paste to range "I17")
            Workbooks("DISH ORDER WORKSHEET.xlsb").Sheets("Inventory Calculations").Range("I17:I500").Copy
            .Range("I17").PasteSpecial Paste:=xlPasteValues

                 
            ActiveWorkbook.SaveAs FileName:=wb.Path & "\" & .Range("Q1").Value & ".xlsx", FileFormat:=51
Perfect. I didn't realize I should have added the sheet in a similar fashion to the first one. Thank you very much for your help.
 
Upvote 0

Forum statistics

Threads
1,215,051
Messages
6,122,871
Members
449,097
Latest member
dbomb1414

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