• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

vba to Extract data from a .xlsm file to another without opening source file

Rodrigues

Member
All
I'm using a piece of vba code file attached to extract data from a .xlsm file to another without opening the source file, the problem is just copies column A values from source file and past them into the wrong rows on the destination files.

Source file (Production.xlsm), worksheet 1 called data, which gets data from a userform and it's set to very hidden; array will be A3 to AR (count all rows as it is filled in).

Destination file (MasterData.xlsm), the data needs to go on Sheet3, from cell A2
Any help will be appreciated.
Thanks R
 

Attachments

  • Production.xlsm
    8.5 KB · Views: 6
  • MasterData.xlsm
    16.4 KB · Views: 6
I'm using a piece of vba code file attached to extract data from a .xlsm file to another without opening the source file,

But your code opens the source file...
Code:
Set src = Workbooks.Open("C:\Production.xlsm", True, True)

You'd need to use different method (such as ADODB), if you don't want to open the source workbook.

At any rate issue is that you have "A2" & iCnt in your code... so starts from row A21.
Code:
    Dim iCnt As Integer
    For iCnt = 1 To iTotalRows
        Worksheets("Sheet3").Range("A2" & iCnt).Formula = src.Worksheets("Sheet1").Range("A" & iCnt).Formula
    Next iCnt

Why ".Formula"? From your description it sounds like it's simple value instead of formula that's contained in the range specified in the source.

Instead of using loop, just copy the range. Something like...
Code:
src.Worksheets("Sheet1").Range("A3:A" & iTotalRows).Copy Worksheets("Sheet3").Range("A2")
 
Yes, these are these read from CLOSED file cases ...
This won't open 'Production.xlsm'-file!!
This is another sample ...
Note1: Production.xlsm, There HAVE TO BE that YELLOW-cell with formula!
Note2: MasterData.xlsm, There HAVE TO BE those YELLOW-cells
Note3: MasterData.xlsm, after the 1st opening You should update link
>> Press [UpDate]-button
>>> Questions?
 

Attachments

  • Production.xlsm
    9.4 KB · Views: 9
  • MasterData.xlsm
    23.1 KB · Views: 9
Back
Top