Copying Excel sheets from a another workbook

I try to copy sheets from another workbook, but the problem that I want to start copying sheets from a certain sheet that I know the name.

I tried to adapt several codes that copy all sheets but I cannot.

Here is a example of my code:

Sub CreationDeBaseDeDonneesAvril2018() Worksheets.Add After:=ThisWorkbook.ActiveSheet Dim Counter As Integer Dim ws As Worksheet Dim FirstMonth As Integer Dim i As Integer Dim wb As Workbook Set wb = Workbooks.Open(") For Each ws In wb If ws.Name = "01m" Then Exit For End If Next ws.Activate Counter = activeworksheet.Count For i = Counter To ActiveWorkbook.Worksheets.Count Worksheets(i).Copy After:=ThisWorkbook.Worksheets(1) Next End Sub 

Thanks you in advance for your help

0

1 Answer

This VBA (Macro) code will help you to Copy certain Sheets from closed Workbook to current Workbook.

Sub CopyFromClosedWBK() Dim wbSource As Workbook Dim wbTarget As Workbook Dim Sht As Worksheet Set wbTarget = ThisWorkbook Set wbSource = Workbooks.Open("C:\FolderName\WhicheverFile.xlsm") wbSource.Sheets("Sheet2").Copy After:=wbTarget.Sheets("Sheet4") wbSource.Close End Sub 

N.B

  • File Path with Source book as well as Folder and Sheet Name's are editable.
  • You may add as many sheets to Copy using, wbSource.Sheets("Sheet2").Copy After:= command line.

You Might Also Like