+ Reply to Thread
Results 1 to 29 of 29

How to link separate Excel files to auto-populate cells

Hybrid View

chrlyd How to link separate Excel... 06-13-2024, 06:35 PM
jindon Re: How to link separate... 06-13-2024, 10:44 PM
chrlyd Re: How to link separate... 06-17-2024, 06:16 PM
TMS Re: How to link separate... 06-17-2024, 06:23 PM
chrlyd Re: How to link separate... 06-19-2024, 06:46 PM
jindon Re: How to link separate... 06-18-2024, 03:20 AM
chrlyd Re: How to link separate... 06-19-2024, 06:48 PM
jindon Re: How to link separate... 06-20-2024, 04:17 AM
chrlyd Re: How to link separate... 06-20-2024, 10:19 AM
TMS Re: How to link separate... 06-19-2024, 07:15 PM
chrlyd Re: How to link separate... 06-19-2024, 07:46 PM
TMS Re: How to link separate... 06-19-2024, 07:48 PM
TMS Re: How to link separate... 06-19-2024, 07:56 PM
chrlyd Re: How to link separate... 06-19-2024, 08:30 PM
TMS Re: How to link separate... 06-19-2024, 08:38 PM
jindon Re: How to link separate... 06-21-2024, 03:57 AM
chrlyd Re: How to link separate... 06-25-2024, 12:54 PM
jindon Re: How to link separate... 06-25-2024, 10:29 PM
TMS Re: How to link separate... 06-21-2024, 07:51 PM
TMS Re: How to link separate... 06-22-2024, 11:43 AM
chrlyd Re: How to link separate... 06-25-2024, 01:45 PM
TMS Re: How to link separate... 06-22-2024, 11:49 AM
jindon Re: How to link separate... 06-25-2024, 07:53 PM
chrlyd Re: How to link separate... 06-27-2024, 12:50 PM
TMS Re: How to link separate... 06-25-2024, 08:07 PM
chrlyd Re: How to link separate... 06-27-2024, 01:03 PM
TMS Re: How to link separate... 06-27-2024, 03:09 PM
jindon Re: How to link separate... 06-27-2024, 11:16 PM
chrlyd Re: How to link separate... 07-02-2024, 03:43 PM
  1. #1
    Registered User
    Join Date
    06-12-2024
    Location
    British Columbia, Canada
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2403 Build 16.0.17425.20236) 32-bit
    Posts
    12

    How to link separate Excel files to auto-populate cells

    Hi, I'm new to the forum and typically only use Excel for it's basic functions. I have multiple .csv files that will be analyzed in R. I would like to link a master dataset Excel file to the .csv files to auto-populate some cells to make data entry more manageable. The .csv files contain additional columns of data, but will share 4 columns in common with the master dataset. As an example:

    I would like to be able to enter EITHER band name OR song title and have the other three columns auto-populate with the appropriate information. Here's what the master sheet would look like:

    Band_Name Song Album Release_Year
    Elton John Runaway Train The One 1992
    Metallica Cure Load 1996
    The Cure Friday I'm in Love Wish 1992
    Radiohead Pyramid Song Amnesiac 2001

    Thanks for any help you can provide!
    Last edited by chrlyd; 06-17-2024 at 06:04 PM.

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: How to link separate Excel files to auto-populate cells

    Can you upload sample csv file(s) and the workbook clearly showing what you are trying to do?

  3. #3
    Registered User
    Join Date
    06-12-2024
    Location
    British Columbia, Canada
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2403 Build 16.0.17425.20236) 32-bit
    Posts
    12

    Re: How to link separate Excel files to auto-populate cells

    I'm sorry, but I'm not able to share my work files. If you have any questions about what I'm trying to do, I can try to clarify.

    File 1 (Regular excel document, containing master data):

    Band_Name Song Album Release_Year
    Elton John Runaway Train The One 1992
    Metallica Cure Load 1996
    The Cure Friday I'm in Love Wish 1992
    Radiohead Pyramid Song Amnesiac 2001


    File 2 (as new data is entered annually, a new file is created and saved as .csv, I want to be able to enter the Band_Name OR Song and have the other three cells (...) auto-populate):
    Date Location Equipment Band_Name Song Album Release_Year
    November 2024 The Treehouse MV01TB Radiohead ... ... ...
    January 2025 Garry's VTG700 ... Cure ... ...
    Last edited by chrlyd; 06-17-2024 at 06:19 PM.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,085

    Re: How to link separate Excel files to auto-populate cells

    A .csv file has only text values separated by commas, no formulae. So you can’t link a .csv file to a master file.

    You can open .csv file in Excel, add formulae to populate one or more columns, and then save the Excel file as a .csv file.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  5. #5
    Registered User
    Join Date
    06-12-2024
    Location
    British Columbia, Canada
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2403 Build 16.0.17425.20236) 32-bit
    Posts
    12

    Re: How to link separate Excel files to auto-populate cells

    Thanks TMS, I think that would be the plan. These files will be created, the data entered, saved and then not modified again, so I think it could work, just need help figuring out what formulae I need to apply.

    Take care,
    chrlyd

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: How to link separate Excel files to auto-populate cells

    chrlyd,

    Too hard to even guess.

    csv file might have duplicate Band_Name etc, so not one to one relations.

  7. #7
    Registered User
    Join Date
    06-12-2024
    Location
    British Columbia, Canada
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2403 Build 16.0.17425.20236) 32-bit
    Posts
    12

    Re: How to link separate Excel files to auto-populate cells

    In my real-life use, there are no duplicate Band_Names or Song titles.

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: How to link separate Excel files to auto-populate cells

    Quote Originally Posted by chrlyd View Post
    In my real-life use, there are no duplicate Band_Names or Song titles.
    Create a new upadated csv file in the same folder.
    Import updated csv in a new worksheet for demo.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    06-12-2024
    Location
    British Columbia, Canada
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2403 Build 16.0.17425.20236) 32-bit
    Posts
    12

    Re: How to link separate Excel files to auto-populate cells

    Thanks, Jindon. I don't see the formulae that's being used to achieve this. To make use of this I would be entering my data in a second sheet on the Mastersheet workbook and then copy and paste the data into a new csv file?

    Thanks for your help!
    chrlyd

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,085

    Re: How to link separate Excel files to auto-populate cells

    File 2 (as new data is entered annually, a new file is created and saved as .csv, I want to be able to enter the Band_Name OR Song and have the other three cells (...) auto-populate):
    There is a slight problem here. A cell can have a value, or a formula, but not both. So, if you provide the Band_Name, you could have a formula to lookup the Band_Name and return the other three values . . . but to separate cells. Similarly, if you provide the Song you could have a formula to return the other three cells. Effectively, you'd be relating one or the other of the search elements.

    You could use a FILTER to get the details from the Master workbook.

    Are you ever missing both the Band Name and the Song? Or, do you ever have both? What if more than one band have recorded a song with the same name? Does that ever happen (in your data)? Obviously it does IRL.

  11. #11
    Registered User
    Join Date
    06-12-2024
    Location
    British Columbia, Canada
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2403 Build 16.0.17425.20236) 32-bit
    Posts
    12

    Re: How to link separate Excel files to auto-populate cells

    Quote Originally Posted by TMS View Post
    There is a slight problem here. A cell can have a value, or a formula, but not both. So, if you provide the Band_Name, you could have a formula to lookup the Band_Name and return the other three values . . . but to separate cells. Similarly, if you provide the Song you could have a formula to return the other three cells. Effectively, you'd be relating one or the other of the search elements.

    You could use a FILTER to get the details from the Master workbook.

    Are you ever missing both the Band Name and the Song? Or, do you ever have both? What if more than one band have recorded a song with the same name? Does that ever happen (in your data)? Obviously it does IRL.
    Thanks, TMS. I'll look into the FILTER option. I'm never missing both Band Name and Song, and I can have both but am trying to simplify the data entry so that I don't need to type both (and the corresponding album name and release year cells). In my real-life use I won't have any duplicate band names or song titles. Sounds like I would be better off if I could try to always enter band name and have the other cells auto-populate from that information?

  12. #12
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,085

    Re: How to link separate Excel files to auto-populate cells

    Sounds like I would be better off if I could try to always enter band name and have the other cells auto-populate from that information?
    Yes. But can't a band have more than one song?

  13. #13
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,085

    Re: How to link separate Excel files to auto-populate cells

    Although you cannot share your live files, you can create redacted sample files (perhaps based on your OP) and upload them.

    We can then consider some options.


    Fast answers need visual help. Please read the yellow banner at the top of this page on how to attach a file and a mocked up solution.

  14. #14
    Registered User
    Join Date
    06-12-2024
    Location
    British Columbia, Canada
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2403 Build 16.0.17425.20236) 32-bit
    Posts
    12

    Re: How to link separate Excel files to auto-populate cells

    Okay, see attached files with an example more aligned with my real-life application.

    Thanks for your help,
    chrlyd
    Attached Files Attached Files

  15. #15
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,085

    Re: How to link separate Excel files to auto-populate cells

    Ok. Late now and I need a laptop. Will look again tomorrow. Makes more sense now

  16. #16
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: How to link separate Excel files to auto-populate cells

    The newly created csv file is the one updated the original csv file from workbook data in the same folder. (main job)
    And new sheet crated is the imported data from newly created csv for the purpose of demo.

    I don't understand about formula etc.

  17. #17
    Registered User
    Join Date
    06-12-2024
    Location
    British Columbia, Canada
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2403 Build 16.0.17425.20236) 32-bit
    Posts
    12

    Re: How to link separate Excel files to auto-populate cells

    Quote Originally Posted by jindon View Post

    I don't understand about formula etc.
    Thanks Jindon,

    The demo works well. My question regarding the formula is that I don't know how to apply this to my actual data. What formula do I enter and where to achieve these results with my data and as a I create new data sheets.

  18. #18
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: How to link separate Excel files to auto-populate cells

    Quote Originally Posted by chrlyd View Post
    My question regarding the formula is that I don't know how to apply this to my actual data. What formula do I enter and where to achieve these results with my data and as a I create new data sheets.
    Do you mean actual header names and/or position of header in csv are different from your files?

    If so, this code will find the position of each header in csv from the header in row(1) of the worksheet.
    Try replace "test" sub with the below, keeping other procedure/function remain intact.
    Sub test()
        Dim fn As String, a, b, s, x, y, temp
        Dim i As Long, ii As Long, dic(1) As Object
        For i = 0 To 1
            Set dic(i) = CreateObject("Scripting.Dictionary")
            dic(i).CompareMode = 1
        Next
        a = Sheets("sheet1").[a1].CurrentRegion.Value
        b = Application.Index(a, 1, 0)
        For i = 2 To UBound(a, 1)
            If a(i, 1) <> "" Then dic(0)(a(i, 1)) = Array(a(i, 1), a(i, 2), a(i, 3), a(i, 4))
            If a(i, 2) <> "" Then dic(1)(a(i, 2)) = Array(a(i, 1), a(i, 2), a(i, 3), a(i, 4))
        Next
        fn = ThisWorkbook.Path & "\example_datasheet.csv"
        x = Split(CreateObject("Scripting.FileSystemObject").OpenTextFile(fn).ReadAll, vbNewLine)
        y = Split(CleanCSV(x(0), Chr(2), Chr(3)), ",")
        For ii = 1 To UBound(b)
            b(ii) = Application.Match(Replace(b(ii), ",", Chr(2)), y, 0)
            If IsError(b(ii)) Then MsgBox "Field " & a(1, ii) & " is missing", vbCritical: Exit Sub
            b(ii) = b(ii) - 1
        Next
        For i = 1 To UBound(x)
            If x(i) <> "" Then
                y = Split(CleanCSV(x(i), Chr(2), Chr(3)), ",")
                For ii = 0 To 1
                    s = Replace(y(b(ii + 1)), Chr(2), ",")
                    If dic(ii).exists(s) Then temp = dic(ii)(s)
                Next
                If IsArray(temp) Then
                    For ii = 1 To UBound(b)
                        If temp(ii - 1) Like "*,*" Then temp(ii - 1) = Chr(34) & temp(ii - 1) & Chr(34)
                        y(b(ii)) = temp(ii - 1)
                    Next
                End If
                x(i) = Replace(Replace(Join(y, ","), Chr(2), ","), Chr(3), """")
            End If
        Next
        fn = Replace(fn, ".csv", "_Updated.csv")
        Open fn For Output As #1
            Print #1, Join(x, vbNewLine);
        Close #1
        ImportCSV fn
    End Sub
    Last edited by jindon; 06-26-2024 at 03:51 AM.

  19. #19
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,085

    Re: How to link separate Excel files to auto-populate cells

    This should work (it did work in my testing):

    Open the Master file
    Open the csv file
    Copy this formula to cell H2.

    Formula: copy to clipboard
    =LET(Mdata,     TRIM('C:\Test\[Example_Mastersheet.xlsx]Sheet1'!$A$1:$D$95),
    MA,INDEX(Mdata,SEQUENCE(ROWS(Mdata)),1), MB,INDEX(Mdata,SEQUENCE(ROWS(Mdata)),2),
    COut,IF(F2<>"",FILTER(Mdata,MA=TRIM(F2),""),IF(G2<>"",FILTER(Mdata,MB=TRIM(G2),""),"")),IFERROR(INDEX(COut,,{3,4}),""))

    Adjust the file location, file name, sheet name and range in the first line of the formula.

    Copy the formula in H2 down to the bottom of the csv file.

    Save and close the csv file.
    Last edited by TMS; 06-22-2024 at 11:43 AM. Reason: Correct error in formula

  20. #20
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,085

    Re: How to link separate Excel files to auto-populate cells

    Corrects an error and makes the formula a little more resilient.

    Formula: copy to clipboard
    =LET(Instructions, "Amend Workbook, Worksheet and Range, as required",  Mdata, [Example_Mastersheet.xlsx]Sheet1!$A$1:$D$1000,
    MA, INDEX(Mdata,SEQUENCE(ROWS(Mdata)),1), MB, INDEX(Mdata,SEQUENCE(ROWS(Mdata)),2),
    COut, IF($F2<>"",FILTER(Mdata,MA=$F2,FILTER(Mdata,MB=$G2,"no match")),
    IF($G2<>"",FILTER(Mdata,MB=$G2,"no match"),"no match")),
    I_34,IFERROR(INDEX(COut,,{3,4}),""),I_3412,IFERROR(INDEX(COut,,{3,4,1,2}),""),I_34)

  21. #21
    Registered User
    Join Date
    06-12-2024
    Location
    British Columbia, Canada
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2403 Build 16.0.17425.20236) 32-bit
    Posts
    12

    Re: How to link separate Excel files to auto-populate cells

    Quote Originally Posted by TMS View Post
    Corrects an error and makes the formula a little more resilient.

    Formula: copy to clipboard
    =LET(Instructions, "Amend Workbook, Worksheet and Range, as required",  Mdata, [Example_Mastersheet.xlsx]Sheet1!$A$1:$D$1000,
    MA, INDEX(Mdata,SEQUENCE(ROWS(Mdata)),1), MB, INDEX(Mdata,SEQUENCE(ROWS(Mdata)),2),
    COut, IF($F2<>"",FILTER(Mdata,MA=$F2,FILTER(Mdata,MB=$G2,"no match")),
    IF($G2<>"",FILTER(Mdata,MB=$G2,"no match"),"no match")),
    I_34,IFERROR(INDEX(COut,,{3,4}),""),I_3412,IFERROR(INDEX(COut,,{3,4,1,2}),""),I_34)
    Thanks, TMS

    It doesn't look like this formula is filling in the name columns, though it works well for filling out the other data. Is there a way to add this capability to the formula? I tried adding the formula to my datasheets, and it worked initially but is now just filling the blanks with "0"... I would appreciate a bit more explanation on the formula you created so I could understand it a bit better to adjust it to my uses as needed. I can see where to amend the workbook, worksheet, and range, but what part of the formula is specifying which cells of the mastersheet to autofill in the datasheet?

    Take care,
    Chrlyd

  22. #22
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,085

    Re: How to link separate Excel files to auto-populate cells

    Sample files
    Attached Files Attached Files

  23. #23
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: How to link separate Excel files to auto-populate cells

    My understanding to your requirement is:

    1) Enter data in Sheet1 in master.xlsm
    2) When button clicked, updates csv directly from the data in Sheet1. (no need to open csv)
    Currently, creates new csv instead of overwriting the original csv.
    If it is confirmed, it can be overwritten the original csv.
    4) Showing the updated result in new worksheet only for your visual demo.

    So, I thought 2) is the main purpose.

    Am I missing something?

  24. #24
    Registered User
    Join Date
    06-12-2024
    Location
    British Columbia, Canada
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2403 Build 16.0.17425.20236) 32-bit
    Posts
    12

    Re: How to link separate Excel files to auto-populate cells

    Quote Originally Posted by jindon View Post
    My understanding to your requirement is:

    1) Enter data in Sheet1 in master.xlsm
    2) When button clicked, updates csv directly from the data in Sheet1. (no need to open csv)
    Currently, creates new csv instead of overwriting the original csv.
    If it is confirmed, it can be overwritten the original csv.
    4) Showing the updated result in new worksheet only for your visual demo.

    So, I thought 2) is the main purpose.

    Am I missing something?

    So, the mastersheet should remain relatively unchanged with maybe a few additions as new plant species are found (I do have other headings from the example file I sent, so thanks for the additional code). I think I understand what to do now - just edit the same .csv file and run the code which will create a new csv. I have never used macros before, so this is new to me. I would like to better understand how to apply this on my own, as I have other data that will be entered in a similar way, but with a different format to the example datasheet.

    I am running into an error with the additional code you sent, "Run-time error "9": Subscript out of range, showing here on the code: If temp(ii - 1) Like "*,*" Then

    Thanks again for all your help!

  25. #25
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,085

    Re: How to link separate Excel files to auto-populate cells

    Just change the last entry from I_34 to I_3412
    Formula: copy to clipboard
    =LET(Instructions, "Amend Workbook, Worksheet and Range, as required",  Mdata, 'C:\Test\[Example_Mastersheet.xlsx]Sheet1'!$A$1:$D$1000,
    MA, INDEX(Mdata,SEQUENCE(ROWS(Mdata)),1), MB, INDEX(Mdata,SEQUENCE(ROWS(Mdata)),2),
    COut, IF($F2<>"",FILTER(Mdata,MA=$F2,FILTER(Mdata,MB=$G2,"no match")),
    IF($G2<>"",FILTER(Mdata,MB=$G2,"no match"),"no match")),
    I_34,IFERROR(INDEX(COut,,{3,4}),""),I_3412,IFERROR(INDEX(COut,,{3,4,1,2}),""),I_3412)
    Last edited by TMS; 06-25-2024 at 08:10 PM.

  26. #26
    Registered User
    Join Date
    06-12-2024
    Location
    British Columbia, Canada
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2403 Build 16.0.17425.20236) 32-bit
    Posts
    12

    Re: How to link separate Excel files to auto-populate cells

    Quote Originally Posted by TMS View Post
    Just change the last entry from I_34 to I_3412
    Formula: copy to clipboard
    =LET(Instructions, "Amend Workbook, Worksheet and Range, as required",  Mdata, 'C:\Test\[Example_Mastersheet.xlsx]Sheet1'!$A$1:$D$1000,
    MA, INDEX(Mdata,SEQUENCE(ROWS(Mdata)),1), MB, INDEX(Mdata,SEQUENCE(ROWS(Mdata)),2),
    COut, IF($F2<>"",FILTER(Mdata,MA=$F2,FILTER(Mdata,MB=$G2,"no match")),
    IF($G2<>"",FILTER(Mdata,MB=$G2,"no match"),"no match")),
    I_34,IFERROR(INDEX(COut,,{3,4}),""),I_3412,IFERROR(INDEX(COut,,{3,4,1,2}),""),I_3412)
    Thanks TMS,

    I made that adjustment and it kind of worked, though the information was not in the correct columns. When I adjusted the formula to refer to my actual mastersheet, rather than the example sheet, it just had a lot of "0"s and "no match"s. I assume I must need to adjust the columns it's referring to within the mastersheet and where that info will be autopopulated within the datasheet, but I'm not sure what to edit.

  27. #27
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,085

    Re: How to link separate Excel files to auto-populate cells

    When I adjusted the formula to refer to my actual mastersheet, rather than the example sheet, it just had a lot of "0"s and "no match"s.
    I can only create solutions for what I am given, not what you are working with IRL.

    If you provide samples of the csv and master file that are truly representative of your live data, I’m sure it can be adapted.

    though the information was not in the correct columns
    You can't replace the search values/columns with the data from the master file without using VBA. Although this thread is in the programming sub-forum, I was trying to avoid VBA, given your stated lack of experience with Excel, let alone VBA.

    I added the names from the master file on the end of the row to give you all the detail. That can easily be shuffled around.

    My thoughts were to provide a simple (albeit manual) process.

    Open the csv file.
    Add the formula and copy it down
    Save the csv file; this would convert the formulae to values

    We can still use that model with a couple of slight tweaks.

    Open the csv file
    Add the formula and copy down
    Manually copy the formulae and paste special values
    Delete the two search columns
    Save the csv file

    Last point: your sample Master file indicated the lookup columns were A:B. If that's not the case, then the formula will not be looking in the right place.

  28. #28
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: How to link separate Excel files to auto-populate cells

    OK, can you replace "test" sub procedure with the below and see how it goes.
    You can add/remove column(s), but Col.B & C should always stay there as the key columns.
    Sub test()
        Dim fn As String, a, b, s, x, y, temp
        Dim i As Long, ii As Long, dic(1) As Object
        For i = 0 To 1
            Set dic(i) = CreateObject("Scripting.Dictionary")
            dic(i).CompareMode = 1
        Next
        a = Sheets("sheet1").[a1].CurrentRegion.Value
        b = Application.Index(a, 1, 0)
        For i = 2 To UBound(a, 1)
            If a(i, 1) <> "" Then dic(0)(a(i, 1)) = Application.Index(a, i, 0)
            If a(i, 2) <> "" Then dic(1)(a(i, 2)) = Application.Index(a, i, 0)
        Next
        fn = ThisWorkbook.Path & "\example_datasheet.csv"
        x = Split(CreateObject("Scripting.FileSystemObject").OpenTextFile(fn).ReadAll, vbNewLine)
        y = Split(CleanCSV(x(0), Chr(2), Chr(3)), ",")
        For ii = 1 To UBound(b)
            b(ii) = Application.Match(Replace(b(ii), ",", Chr(2)), y, 0)
            If IsError(b(ii)) Then MsgBox "Field " & a(1, ii) & " is missing", vbCritical: Exit Sub
            b(ii) = b(ii) - 1
        Next
        For i = 1 To UBound(x)
            If x(i) <> "" Then
                y = Split(CleanCSV(x(i), Chr(2), Chr(3)), ",")
                For ii = 0 To 1
                    s = Replace(y(b(ii + 1)), Chr(2), ",")
                    If dic(ii).exists(s) Then temp = dic(ii)(s)
                Next
                If IsArray(temp) Then
                    For ii = 1 To UBound(b)
                        If temp(ii) Like "*,*" Then temp(ii - 1) = Chr(34) & temp(ii - 1) & Chr(34)
                        y(b(ii)) = temp(ii)
                    Next
                End If
                x(i) = Replace(Replace(Join(y, ","), Chr(2), ","), Chr(3), """")
            End If
        Next
        fn = Replace(fn, ".csv", "_Updated.csv")
        Open fn For Output As #1
            Print #1, Join(x, vbNewLine);
        Close #1
        ImportCSV fn
    End Sub

  29. #29
    Registered User
    Join Date
    06-12-2024
    Location
    British Columbia, Canada
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2403 Build 16.0.17425.20236) 32-bit
    Posts
    12

    Re: How to link separate Excel files to auto-populate cells

    Quote Originally Posted by TMS View Post
    I can only create solutions for what I am given, not what you are working with IRL.

    If you provide samples of the csv and master file that are truly representative of your live data, I’m sure it can be adapted.

    Last point: your sample Master file indicated the lookup columns were A:B. If that's not the case, then the formula will not be looking in the right place.
    Thanks, TMS

    I understand you're limited to what I can provide. I was naively hoping the solution would be simpler than it turned out to be. I thought I would be able to learn a new formula or tool to auto-populate the information I needed and I would be able to modify the solution to fit my live data as well as a couple other data sheet formats I have that can be auto-populated from the same master sheet. I can link all my real data, if you think that's the best option

    Yes, the lookup columns will always be A:B. I just have one other column in there. One issue is this is a new study, and there may be additional data added or removed depending on what we find useful. So, I was hoping to learn how the auto-populate function works a bit better so I can make adjustments as needed.

    Thanks for all your help so far.

    Chrlyd

+ 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. Auto link from excel to folder's files
    By sherif114 in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 11-06-2020, 09:46 AM
  2. Replies: 3
    Last Post: 06-25-2020, 10:43 PM
  3. [SOLVED] How to link two sheets in two separate Excel files
    By BNCOXUK in forum Excel General
    Replies: 3
    Last Post: 11-30-2012, 09:17 AM
  4. Auto populate data from multiple cells on separate worksheet
    By Talance in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-01-2011, 07:19 PM
  5. Link and auto-populate cells in workbooks
    By Larry in forum Excel - New Users/Basics
    Replies: 0
    Last Post: 06-22-2006, 11:00 AM
  6. [SOLVED] How can I create a link between cells in two separate Excel sheet
    By Dawnmarie in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-18-2006, 01:40 PM
  7. How do I link separate Excel files to one spreadsheet?
    By eklushin in forum Excel General
    Replies: 0
    Last Post: 01-06-2006, 04:40 PM

Tags for this Thread

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