Copying from opened files into one workbook

djphill

New Member
Joined
Nov 4, 2002
Messages
6
I have created a loop which will look into a directory and list and open the files in chronological order. What I want to do is as the loop is running, is to copy data from the opened file into the workbook I am running the macro from: with each sheet copied being copied onto a new sheet in the master workbook. Is this possible? I have tried to do this before but in keeps indexing as sheet1(1)sheet1(2) (and running out of indices) rather than sheet1,Sheet2. Help??
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Richie(UK)

MrExcel MVP
Joined
May 17, 2002
Messages
3,329
Hi djphill,

Welcome to the board. :)

How about calling a routine something like this from your workbook open routine:

<pre>Sub CopySheets()
Dim newsheet As Worksheet, j As Integer, wsname As String

For j = 1 To ActiveWorkbook.Sheets.Count
With ActiveWorkbook.Worksheets(j)
wsname = .Name
.UsedRange.Copy
End With
Set newsheet = ThisWorkbook.Sheets.Add(After:=Worksheets(Worksheets.Count))
'add sheet to copy to
newsheet.Name = wsname
'give it the same name as the copied sheet
newsheet.Range("A1").PasteSpecial
Application.CutCopyMode = False 'clear the clipboard
Set newsheet = Nothing 'clear memory
Next j

End Sub</pre>
HTH
 

Forum statistics

Threads
1,144,291
Messages
5,723,527
Members
422,502
Latest member
barakgahtan

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
Top