worksheet help

Excelnoobisme

Board Regular
Joined
Nov 19, 2010
Messages
128
Hi,

Right now im using the following code to open all the files in a certain folder and copy the data into a spreadsheet.

Dim path As Variant
Dim excelfile As Variant
path = "C:\Program Files\Data"
Dim wb1 As Workbook, wb2 As Workbook
Set wb1 = ActiveWorkbook
Application.DisplayAlerts = False

excelfile = Dir(path & "*.xlsm")

Do While excelfile <> ""
Workbooks.Open Filename:=path & excelfile
Set wb2 = ActiveWorkbook
excelfile = Dir
Sheets("Summary").Select
Range("A3").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Copy
Windows("Test").Activate
Range("A1").End(xlDown).Select
ActiveCell.Offset(1, 0).PasteSpecial xlPasteValues
wb2.Close savechanges:=False
Loop

how can i change to make it copy each files into different worksheet instead of 1 worksheet?
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
any1 can help me pls. I wish to have it copy into different worksheets depend on how many file there is in the folder.
 
Upvote 0
any1 can help me pls. I wish to have it copy into different worksheets depend on how many file there is in the folder.


This should be tested first.

Code:
Sub excelnoobisme()
Dim path As Variant
Dim excelfile As Variant
Dim i As Long
path = "C:\Program Files\Data"
Dim wb1 As Workbook, wb2 As Workbook
Set wb1 = ActiveWorkbook
Application.DisplayAlerts = False

excelfile = Dir(path & "*.xlsm")
i = 1
Do While excelfile <> ""
Workbooks.Open Filename:=path & excelfile
Set wb2 = ActiveWorkbook
excelfile = Dir
Sheets("Summary").Select
Range("A3").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Copy
Windows("Test").Activate
Worksheets.Add Before:=Sheets("Sheet1")
ActiveSheet.Name = "New Sheet" & i
Range("A1").Offset(1, 0).PasteSpecial xlPasteValues
wb2.Close savechanges:=False
i = i + 1
Loop

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,607
Messages
6,179,871
Members
452,948
Latest member
UsmanAli786

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