Duplication of Excel sheets to a newly created file

Toyall

New Member
Joined
Feb 24, 2023
Messages
1
Office Version
  1. 2021
Platform
  1. Windows
Dear all,

I am having a quite difficulty regarding VBA.

Currently, I am trying to duplicate an excel sheet that is from another workingfile with application of VBA on current working file.

Sub BringingSheet()

Dim fileName As String
Dim filePath As String
Dim shtName As String
Dim NewlyCreatedFile As Workbook

Set NewlyCreatedFile = Workbooks.Add

' To be Duplicated

Dim i As Integer
Dim n As Integer

'Input of the file that has the sheet to be duplicated
file = ThisWorkbook.Sheets("Sheet1").Cells(2, 3).Value
'Input of the number that is to be outputed
n = ThisWorkbook.Sheets("Sheet1").Cells(4, 3).Value

'Path of the sheet to be duplicated
filePath = ThisWorkbook.Path + "\" + file

'Opening of the file
Workbooks.Open fileName:=filePath

'Bringing the copy - loop // 1 is the name of the sheet

For i = 1 To n

ActiveWorkbook.Sheets("1").Copy After:=NewlyCreatedFile.Sheets(1)

Next

Workbooks(file).Close (False)


End Sub

Additionally, I would like the sheet to be numbered as 1, 2, 3...to n

Thanks
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Forum statistics

Threads
1,214,812
Messages
6,121,699
Members
449,048
Latest member
81jamesacct

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