1

any and all help is greatly appreciated.

Description: I have an excel file with several sheets of data. I need to copy ALL of the data from multiple sheets, create a NEW excel file, and paste that data into multiple sheets. So if I have the following:

excelfile1.xlsx - sheet1 - sheet2

I need to select sheet1, copy all the data in sheet1, create a new excel file and paste the sheet1 data into the new file on sheet1new, and then need to do the same with sheet2.

Here is my code for processing 1 sheet (but am not sure how to ask it to process the actions for the 2nd sheet, which is where I need some guidance):

Dim Directory As String
Dim Filename As String

Directory = Range("directory").Value
Filename = Range("filename").Value





Sheets("RHD").Select

Cells.Select
Range("N15").Activate
Selection.Copy

Workbooks.Add
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False

ActiveWorkbook.SaveAs Filename:=Directory & Filename, _
    FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWindow.Close

Sheets("I&S").Select
2
  • 1
    Why not just save a copy of the workbook? If you have worksheets you don't need, you can then delete them from the copied workbook Commented Jan 3, 2019 at 19:23
  • Because the data in the sheets in the existing file changes daily, and I need a copy of each days data in a separate file for another reason.
    – Riyer
    Commented Jan 3, 2019 at 19:33

1 Answer 1

1
Worksheets(Array("Sheet1", "Sheet2")).Copy
With ActiveWorkbook
 .SaveAs Filename:=Environ("TEMP") & "\New3.xlsx", FileFormat:=xlOpenXMLWorkbook 
 .Close SaveChanges:=False 
End With 

from docs.microsoft.com

1
  • Cheers! Did the trick
    – Riyer
    Commented Jan 3, 2019 at 23:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .