LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ray Ray is offline
external usenet poster
 
Posts: 267
Default Help with copying range btw workbooks (advanced example)

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

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Advanced Filter - Copying to location other than current sheet? Maki Excel Discussion (Misc queries) 6 January 13th 10 08:10 AM
Advanced filtering and shared workbooks Les Excel Discussion (Misc queries) 0 July 24th 07 03:08 PM
Very advanced links through excel to several workbooks riakilly Excel Discussion (Misc queries) 0 August 30th 06 11:11 AM
Shared workbooks, advanced filters, and refreshing pivot tables Lara[_2_] Excel Programming 0 April 15th 04 11:59 PM
how to? set my range= my UDF argument (range vs. value in range) [advanced?] Keith R[_3_] Excel Programming 2 August 11th 03 05:55 PM


All times are GMT +1. The time now is 07:21 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"