jchula
08-05-2013, 09:58 AM
Hi,
I want to combine multiple workbooks (sheet1 in every workbook) in one destination workbook.
The destination workbook must have the multiple worksheets with the name of source workbook.
Example:
File Store1.xlsx with sheet1; Store2.xlsx with sheet1; Store3.xlsx with sheet1;...
I want a destination workbook ALLSTORES.xlsx with worksheets Store1; Store2; Store3;...
i have this code but this dont give me the names of the stores; give me sheet1, sheet2, sheet3,....
Thks
Public Sub test()
Dim myFile As String, sh As Worksheet, myRange As Range
Const myPath = "C:\Users\" ' to be modified
Workbooks.Add 1 ' Add a new workbook
myFile = Dir(myPath & "*.xlsx")
Do While myFile <> ""
Set sh = ActiveWorkbook.Sheets.Add()
Workbooks.Open myPath & myFile
Cells.Copy Destination:=sh.Range("A1")
' Set myRange = ActiveSheet.UsedRange
' Set myRange = myRange.Offset(1).Resize(myRange.Rows.Count - 1)
' myRange.Copy sh.Range("A65000").End(xlUp).Offset(1)
ActiveSheet.Name = myFile
Workbooks(myFile).Close False
myFile = Dir
Loop
End Sub
I want to combine multiple workbooks (sheet1 in every workbook) in one destination workbook.
The destination workbook must have the multiple worksheets with the name of source workbook.
Example:
File Store1.xlsx with sheet1; Store2.xlsx with sheet1; Store3.xlsx with sheet1;...
I want a destination workbook ALLSTORES.xlsx with worksheets Store1; Store2; Store3;...
i have this code but this dont give me the names of the stores; give me sheet1, sheet2, sheet3,....
Thks
Public Sub test()
Dim myFile As String, sh As Worksheet, myRange As Range
Const myPath = "C:\Users\" ' to be modified
Workbooks.Add 1 ' Add a new workbook
myFile = Dir(myPath & "*.xlsx")
Do While myFile <> ""
Set sh = ActiveWorkbook.Sheets.Add()
Workbooks.Open myPath & myFile
Cells.Copy Destination:=sh.Range("A1")
' Set myRange = ActiveSheet.UsedRange
' Set myRange = myRange.Offset(1).Resize(myRange.Rows.Count - 1)
' myRange.Copy sh.Range("A65000").End(xlUp).Offset(1)
ActiveSheet.Name = myFile
Workbooks(myFile).Close False
myFile = Dir
Loop
End Sub