C
Crownman
I have a set of about 50 source files, each with 5 named ranges (one
name range on each of 5 tabs). I am trying to create a macro to copy
the named ranges for each of the source files to the corresponding tab
of a destination file so that the destination file contains a column
for each source file on each tab. Thus far, I have the following
code:
Dim wbOther As Workbook
Dim PathsList As Range
Dim i As Range
Dim ThePath As String
Dim TheFile As String
Sub CopyBuysheets()
With Sheets("FOLDERS")
Set PathsList = .Range("A2", .Range("A" &
Rows.Count).End(xlUp))
End With
Set wbThis = ThisWorkbook
For Each i In PathsList
ThePath = i.Value
ChDir ThePath
TheFile = Dir("*.xls")
Do While TheFile <> ""
Application.EnableEvents = False
Set wbOther = Workbooks.Open(ThePath & "\" &
TheFile)
Sheets("ABSOLUT").Select
Application.EnableEvents = True
With wbThis.Sheets("ABSOLUT")
Range("ABSOLUT_TOTAL").Copy
.Range("ABSOLUT_START").End(xlRight).Offset(-1,
1).PasteSpecial Paste:=xlPasteValues
Range("CRUZAN_TOTAL").Copy
.Range("CRUZAN_START").End(xlRight).Offset(-1,
1).PasteSpecial Paste:=xlPasteValues
Range("LEVEL_TOTAL").Copy
.Range("LEVEL_START").End(xlRight).Offset(-1,
1).PasteSpecial Paste:=xlPasteValues
Range("PLYMOUTH_TOTAL").Copy
.Range("PLYMOUTH_START").End(xlRight).Offset(-1,
1).PasteSpecial Paste:=xlPasteValues
Range("FRIS_TOTAL").Copy
.Range("FRIS_START").End(xlRight).Offset(-1,
1).PasteSpecial Paste:=xlPasteValues
End With
wbOther.Close SaveChanges:=False
TheFile = Dir
Loop
Next i
End Sub
The macro fails at the following line with the error message
"Application defined or object defined error."
..Range("ABSOLUT_START").End(xlRight).Offset(-1, 1).PasteSpecial
Paste:=xlPasteValues
Any advice would be appreciated. TIA
Crownman
name range on each of 5 tabs). I am trying to create a macro to copy
the named ranges for each of the source files to the corresponding tab
of a destination file so that the destination file contains a column
for each source file on each tab. Thus far, I have the following
code:
Dim wbOther As Workbook
Dim PathsList As Range
Dim i As Range
Dim ThePath As String
Dim TheFile As String
Sub CopyBuysheets()
With Sheets("FOLDERS")
Set PathsList = .Range("A2", .Range("A" &
Rows.Count).End(xlUp))
End With
Set wbThis = ThisWorkbook
For Each i In PathsList
ThePath = i.Value
ChDir ThePath
TheFile = Dir("*.xls")
Do While TheFile <> ""
Application.EnableEvents = False
Set wbOther = Workbooks.Open(ThePath & "\" &
TheFile)
Sheets("ABSOLUT").Select
Application.EnableEvents = True
With wbThis.Sheets("ABSOLUT")
Range("ABSOLUT_TOTAL").Copy
.Range("ABSOLUT_START").End(xlRight).Offset(-1,
1).PasteSpecial Paste:=xlPasteValues
Range("CRUZAN_TOTAL").Copy
.Range("CRUZAN_START").End(xlRight).Offset(-1,
1).PasteSpecial Paste:=xlPasteValues
Range("LEVEL_TOTAL").Copy
.Range("LEVEL_START").End(xlRight).Offset(-1,
1).PasteSpecial Paste:=xlPasteValues
Range("PLYMOUTH_TOTAL").Copy
.Range("PLYMOUTH_START").End(xlRight).Offset(-1,
1).PasteSpecial Paste:=xlPasteValues
Range("FRIS_TOTAL").Copy
.Range("FRIS_START").End(xlRight).Offset(-1,
1).PasteSpecial Paste:=xlPasteValues
End With
wbOther.Close SaveChanges:=False
TheFile = Dir
Loop
Next i
End Sub
The macro fails at the following line with the error message
"Application defined or object defined error."
..Range("ABSOLUT_START").End(xlRight).Offset(-1, 1).PasteSpecial
Paste:=xlPasteValues
Any advice would be appreciated. TIA
Crownman