R
Ray
hello -
I need to pull a specified range from approx 30 workbooks and paste
this info into the corresponding column in my summary workbook. I've
gotten my code to work to a point (open source file, copy range, paste
into a pre-specified column in destination workbook), but when I try
to modify the code to LOOK for the correct column, it all goes to
H***.
Here are the specs, with my current code below:
* range to copy: J5:J500 from source WB (called 'mybook' in code)
* identifying value (of source WB) in Sheets("Dashboard").Range("E13")
(called 'getstore' in code)
* find 'getstore' value in Row3 of destination WB and identify column
('Tcol' in code)
* paste copied range (J5:J500) in correct column, cells 5:500
Here's the current code (the 'meat' of it, anyway):
Set basebook = ThisWorkbook
basebook.Sheets("From FC
pkgs").Range("C5:AB500").ClearContents '
'Fill the array(myFiles)with the list of Excel files in the folder
Fnum = 0
Do While FilesInPath <> ""
Fnum = Fnum + 1
ReDim Preserve MyFiles(1 To Fnum)
MyFiles(Fnum) = FilesInPath
FilesInPath = Dir()
Loop
total = Fnum
If Fnum > 0 Then
For Fnum = LBound(MyFiles) To UBound(MyFiles)
Set mybook = Workbooks.Open(MyPath & MyFiles(Fnum), 0,
True)
Application.StatusBar = "Now processing File " & Fnum & "
of " & total
' Isolates the store number from the workbook name
getstore = mybook.Sheets("Dashboard").Range("E13").Value
getstore = Format(getstore, "000") 'necessary b/c
some stores have leading zeros
mybook.Sheets("P&L Acct Detail").Unprotect ("busnav")
Set sourceRange = mybook.Sheets("P&L Acct
Detail").Range("J5:J500")
Tcol = basebook.Worksheets("From FC
pkgs").Range("3:3").Find(getstore, LookIn:=xlValues,
LookAt:=xlWhole).Column
Trange = Tcol & "5:" & Tcol & "500"
Set destrange = basebook.Sheets("From FC
pkgs").Range(Trange)
destrange.Value = sourceRange.Value
mybook.Close savechanges:=False
Next Fnum
End If
The last time I ran this (with just one WB in a test folder), the
correct range was copied, but instead of into just one column, it was
copied into EVERY column in the destination workbook. The really
strange part is that the paste was started in row35 ..... and I don't
mention row35 anywhere in my code. Or do I???
TIA,
Ray
I need to pull a specified range from approx 30 workbooks and paste
this info into the corresponding column in my summary workbook. I've
gotten my code to work to a point (open source file, copy range, paste
into a pre-specified column in destination workbook), but when I try
to modify the code to LOOK for the correct column, it all goes to
H***.
Here are the specs, with my current code below:
* range to copy: J5:J500 from source WB (called 'mybook' in code)
* identifying value (of source WB) in Sheets("Dashboard").Range("E13")
(called 'getstore' in code)
* find 'getstore' value in Row3 of destination WB and identify column
('Tcol' in code)
* paste copied range (J5:J500) in correct column, cells 5:500
Here's the current code (the 'meat' of it, anyway):
Set basebook = ThisWorkbook
basebook.Sheets("From FC
pkgs").Range("C5:AB500").ClearContents '
'Fill the array(myFiles)with the list of Excel files in the folder
Fnum = 0
Do While FilesInPath <> ""
Fnum = Fnum + 1
ReDim Preserve MyFiles(1 To Fnum)
MyFiles(Fnum) = FilesInPath
FilesInPath = Dir()
Loop
total = Fnum
If Fnum > 0 Then
For Fnum = LBound(MyFiles) To UBound(MyFiles)
Set mybook = Workbooks.Open(MyPath & MyFiles(Fnum), 0,
True)
Application.StatusBar = "Now processing File " & Fnum & "
of " & total
' Isolates the store number from the workbook name
getstore = mybook.Sheets("Dashboard").Range("E13").Value
getstore = Format(getstore, "000") 'necessary b/c
some stores have leading zeros
mybook.Sheets("P&L Acct Detail").Unprotect ("busnav")
Set sourceRange = mybook.Sheets("P&L Acct
Detail").Range("J5:J500")
Tcol = basebook.Worksheets("From FC
pkgs").Range("3:3").Find(getstore, LookIn:=xlValues,
LookAt:=xlWhole).Column
Trange = Tcol & "5:" & Tcol & "500"
Set destrange = basebook.Sheets("From FC
pkgs").Range(Trange)
destrange.Value = sourceRange.Value
mybook.Close savechanges:=False
Next Fnum
End If
The last time I ran this (with just one WB in a test folder), the
correct range was copied, but instead of into just one column, it was
copied into EVERY column in the destination workbook. The really
strange part is that the paste was started in row35 ..... and I don't
mention row35 anywhere in my code. Or do I???
TIA,
Ray