+ Reply to Thread
Results 1 to 10 of 10

Two questions about adding rows, copying data between multiple Excel files

  1. #1
    Forum Contributor
    Join Date
    02-05-2021
    Location
    Netherlands
    MS-Off Ver
    Microsoft Excel 365 (version 2022, Build 14931.20764)
    Posts
    180

    Two questions about adding rows, copying data between multiple Excel files

    Dear Excel specialist,

    A have question, but first allow me to provide some context.

    I created VBA code that opens sequentially all workbooks in a source directory (all files contain the same format/structure, but the contents vary).

    At high level:
    - Data is sequentially copied and paste from the (source) workbook files, range (R7:S500) to 1 destination file
    - File is closed, next file opened
    - All data (again) will be past in the destination file, but one column to the right -> (next column i=i+2 counter), otherwise the original data will be overwritten.
    - Redo from start until no files are found

    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Currently, I have 2 challenges.

    1. I don't want to open the (source) workbooks (visually) while gathering the data.
    I would like to have a kind of background process. For example: (https://www.exceldemy.com/excel-vba-...thout-opening/)

    2. Each file in de source directory contains this cell information (content may vary)
    a. Refresh_Date = Cell B1
    b. Department_Name = Cell B2
    c. Domain_Owner_Name = Cell C1

    I would like to add these (a, b, c) at the top of each (to be added) column that is filled with the data of the source files.
    I am trying to achieve this, but unfortunately, it does not work.


    -----------------------------------------------------------------------------------------------

    For example (please see attached example)

    Blank row
    02-02-2023 (This is the date field from cell B1)
    Finance (This is the department name from Cell B2)
    Piet Compete (This is the owner name from Cell C1)
    Blank row

    (R7:S500) data from the range.


    -----------------------------------------------------------------------------------------------

    Is it possible to help me out with this question (btw, I am not a programmer)?
    Normally I add the original Excel files to provide an example, but this is not allowed, because it contains a lot of company information (i.e. confidential).

    Thank you in advance for any support.

    Please Login or Register  to view this content.
    Attached Images Attached Images

  2. #2
    Valued Forum Contributor
    Join Date
    12-01-2011
    Location
    Philippines
    MS-Off Ver
    Excel 2016
    Posts
    949

    Re: Two questions about adding rows, copying data between multiple Excel files

    try, obviously untested

    Please Login or Register  to view this content.
    Last edited by k1dr0ck; 03-25-2023 at 03:38 AM.

  3. #3
    Forum Contributor
    Join Date
    02-05-2021
    Location
    Netherlands
    MS-Off Ver
    Microsoft Excel 365 (version 2022, Build 14931.20764)
    Posts
    180

    Re: Two questions about adding rows, copying data between multiple Excel files

    Hi k1dr0ck,

    Your code works like a charm. Thank you for that (very happy)!
    I have just one small question...
    Some cells contain references; therefore, some results are showing a #REF error in the "paste" result.

    Is it possible to copy the cells without the references. So only the values with the existing markup like colors, borders and so on?
    Please see attached file with the result.

    Thank you very much!! 😊

  4. #4
    Forum Contributor
    Join Date
    02-05-2021
    Location
    Netherlands
    MS-Off Ver
    Microsoft Excel 365 (version 2022, Build 14931.20764)
    Posts
    180

    Re: Two questions about adding rows, copying data between multiple Excel files

    This does not work...

    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor
    Join Date
    12-01-2011
    Location
    Philippines
    MS-Off Ver
    Excel 2016
    Posts
    949

    Re: Two questions about adding rows, copying data between multiple Excel files

    maybe


    Please Login or Register  to view this content.
    Last edited by k1dr0ck; 03-27-2023 at 11:14 PM.

  6. #6
    Forum Contributor
    Join Date
    02-05-2021
    Location
    Netherlands
    MS-Off Ver
    Microsoft Excel 365 (version 2022, Build 14931.20764)
    Posts
    180

    Re: Two questions about adding rows, copying data between multiple Excel files

    Hi k1dr0ck,

    Thank you very much for you help. I am very happy with the results (works like a charm!)
    I will close the thread and add reputation.
    Thank you again.

  7. #7
    Forum Contributor
    Join Date
    02-05-2021
    Location
    Netherlands
    MS-Off Ver
    Microsoft Excel 365 (version 2022, Build 14931.20764)
    Posts
    180

    Re: Two questions about adding rows, copying data between multiple Excel files

    Hi k1dr0ck,

    Sorry for the inconvenience, but I have one question left (I can open a new thread, but you know the code).
    The script works fine, but it removes the formulas in the source files. Do you know what the reason could be?
    Thank you in advance for your answer! :-)

    PS.
    I changed some variables, because I got an overflow error (from (i, j) to arr(x, y) = arr(x, y)

    Please Login or Register  to view this content.
    Last edited by NewBee_HS; 03-29-2023 at 08:47 AM. Reason: Added some text

  8. #8
    Valued Forum Contributor
    Join Date
    12-01-2011
    Location
    Philippines
    MS-Off Ver
    Excel 2016
    Posts
    949

    Re: Two questions about adding rows, copying data between multiple Excel files

    the array that i added will replace the formulas with its actual values in the workbook
    so when copied there will be no #Ref errors
    but since you are not saving the workbook when closing it should not save the changes

    try using
    Please Login or Register  to view this content.
    Last edited by k1dr0ck; 03-29-2023 at 09:13 AM.

  9. #9
    Forum Contributor
    Join Date
    02-05-2021
    Location
    Netherlands
    MS-Off Ver
    Microsoft Excel 365 (version 2022, Build 14931.20764)
    Posts
    180

    Re: Two questions about adding rows, copying data between multiple Excel files

    It works!! :-)
    Thank you again!

  10. #10
    Valued Forum Contributor
    Join Date
    12-01-2011
    Location
    Philippines
    MS-Off Ver
    Excel 2016
    Posts
    949

    Re: Two questions about adding rows, copying data between multiple Excel files

    since you were actually using formulas your initial code was actually better than using an array

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. VBA code to copy data from Excel by rows to multiple text files
    By hmlaw in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-21-2020, 02:18 AM
  2. Copying data from one excel file and pasting into multiple excel files
    By tonybeo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-26-2014, 06:23 PM
  3. Copying Data from one Sheet to another and adding rows to accomodate
    By whammond597 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-16-2014, 04:59 PM
  4. Replies: 1
    Last Post: 08-13-2013, 06:16 PM
  5. copying data from many files and adding to a separate file (PLEASE HELP!)
    By etodem in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-13-2013, 05:46 PM
  6. Copying Data from multiple excel files
    By rugbyfitz in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-10-2008, 04:34 AM
  7. [SOLVED] Macro copying info/data in multiple excel files into one summary file.
    By Jskasango in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-06-2006, 03:30 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1