+ Reply to Thread
Results 1 to 4 of 4

Help with macro to copy new data into my worksheet

  1. #1
    Registered User
    Join Date
    05-13-2019
    Location
    Louisiana
    MS-Off Ver
    2016
    Posts
    76

    Help with macro to copy new data into my worksheet

    I have a pretty complex workbook that I am going to try to explain the best I can. If I select the "Create Field Book" button on the "Merge" worksheet, the macro does a web query to find a list of work items for a construction project. This data is pasted to the "Data" worksheet. The macro then looks at the list on "Data", finds a template in my template folder for each work item, and then creates a new worksheet for each work item in the list using this template. While it creates this worksheet for each work item, it fills in some header information for that work item that also comes from "Data". The sheets are ordered by the digits that appear before the first underscore in the tab name with the numbers ranging from 1 to 999. Sometimes new items are added to the list and I have another macro that does the same thing but only brings in the new items that were added. This works great until an item is added that goes before one that has already been created. For instance, if I have an existing sheet that starts with 901 and then I add a new sheet that starts with 8. This messes up my header information because the cells for that data are formulas that reference the "Data" sheet. So now the old 901 item references where the 8 item is because that sheet was not changed when the "Data" sheet was updated with the new items. So now the 901 and 8 work item reference row 18. Is there a way to fix this where the 901 item references row 19 after bringing in the 8 work item? Keep in mind that the number of sheets and the number of the work items can vary greatly so it would have to be a dynamic solution. I hope this makes since. I have attached my templates and the workbook where I am having this issue. Also the code for the problem macro is below.

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

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,215

    Re: Help with macro to copy new data into my worksheet

    I would change as follows:

    In the TEMPLATE sheets: put "Item Code" in D4 e.g CI-107-0010 (can be derived from sheet name)

    then use INDEX/MATCH to retrieve values from DATA based on "Item Code"

    e.g

    in D2

    =INDEX(Data!$A$11:$H$100,MATCH($D$4,Data!$C$11:$C$100,0),1)

    Change highlighted for other fields

    e.g

    D9

    =INDEX(Data!$A$11:$H$100,MATCH($D$4,Data!$C$11:$C$100,0),8)

    Any changes in DATA are then automatically reflected in the template sheets
    Attached Files Attached Files
    Last edited by JohnTopley; 09-30-2023 at 06:23 AM.
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  3. #3
    Registered User
    Join Date
    05-13-2019
    Location
    Louisiana
    MS-Off Ver
    2016
    Posts
    76

    Re: Help with macro to copy new data into my worksheet

    This may work. I will have to test. But sometimes there are multiple sheets with the same item code. These are differentiated by the Line Item#, and these line item numbers are different on every project. I dont know if this would cause a problem with that or not.
    Last edited by AliGW; 10-02-2023 at 09:50 AM. Reason: Please do NOT quote unnecessarily! Use the QUICK REPLY button instead.

  4. #4
    Registered User
    Join Date
    05-13-2019
    Location
    Louisiana
    MS-Off Ver
    2016
    Posts
    76

    Re: Help with macro to copy new data into my worksheet

    Quote Originally Posted by JohnTopley View Post
    I would change as follows:

    In the TEMPLATE sheets: put "Item Code" in D4 e.g CI-107-0010 (can be derived from sheet name)

    then use INDEX/MATCH to retrieve values from DATA based on "Item Code"

    e.g

    in D2

    =INDEX(Data!$A$11:$H$100,MATCH($D$4,Data!$C$11:$C$100,0),1)

    Change highlighted for other fields

    e.g

    D9

    =INDEX(Data!$A$11:$H$100,MATCH($D$4,Data!$C$11:$C$100,0),8)

    Any changes in DATA are then automatically reflected in the template sheets
    I got this to work with a slight modification. I made the formula match the line item # to help in the cases where there were multiples of the same item code. Thanks for your help.

+ 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. Replies: 1
    Last Post: 03-15-2017, 09:44 AM
  2. Macro to copy data from multiple worksheet cells in to a single Master worksheet
    By thunt13 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-08-2015, 03:24 PM
  3. Replies: 3
    Last Post: 05-26-2014, 02:21 AM
  4. [SOLVED] Macro/VBA code to Copy data from primary worksheet to a worksheet opened by macro
    By MHamid in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-30-2013, 11:10 AM
  5. Macro Button to copy data from one worksheet to second worksheet with criteria
    By vortex1fire in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-05-2013, 06:24 PM
  6. Replies: 1
    Last Post: 08-29-2012, 07:11 PM
  7. [SOLVED] Macro to copy cells from one worksheet to another copies worksheet data as image instead??
    By michaeljoeyeager in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-13-2012, 11:26 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