+ Reply to Thread
Results 1 to 29 of 29

VBA to update Sheet 2 the Location from Sheet 1. Thank you very much

  1. #1
    Registered User
    Join Date
    12-11-2023
    Location
    los altos, ca
    MS-Off Ver
    2016
    Posts
    38

    VBA to update Sheet 2 the Location from Sheet 1. Thank you very much

    *********THANKS MILLIONS JohnTopley for your SUPER POWERFUL, QUICK CODES. You're Super Genius. Your code works like a MIRACLE. Thanks a lot for your time & talent.
    I tried to add the reputation for your kind, quick help but the system does not allow me as it says the same post while it is actually different issues.
    I wish I could add millions stars to reputation. BIG THANKS JOHN TOPLEY******

    The problem is now SOLVED BY JOHN TOPLEY. THANKS MILLIONS JOHN !

    Hi Super Coders

    Hope you have a great new week.
    I urgently need your talent please.

    Attached are 2 Excel files with different numbers of Column Headings.
    However, both have 2 common Column Headings: ClientID (Primary Key) & Location.
    The number of Column Headings in both File 1 and File 2 could be changing more over time.

    File 1 (>300,000 records) - downloaded file that comes with 6 Protected Sheets which contain the Location data that File 2 needs.
    File 2 (>3,000 records) - where The column named Location needs to be UPDATED.

    My job is to update column Location of File 2 for the matching Client ID.

    *******SPECIAL THANKS TO JohnTopley FOR THE 1ST POST. THIS IS RE-POST with additional info. thanks again John ***********


    Thank you so much for your time & help
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by jojo4santa; 03-14-2024 at 01:56 PM. Reason: VBA or Formula to update File 2 with data from File 1

  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,317

    Re: VBA to update Sheet 2 the Location from Sheet 1. Thank you very much

    Try

    in H2 and copy down

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    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
    12-11-2023
    Location
    los altos, ca
    MS-Off Ver
    2016
    Posts
    38

    Re: VBA to update Sheet 2 the Location from Sheet 1. Thank you very much

    Thank you so much John Topley for your super quick, magic code. It works great. I had added reputation to you. thanks millions

  4. #4
    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,317

    Re: VBA to update Sheet 2 the Location from Sheet 1. Thank you very much

    You're welcome and thank you for the rep.

  5. #5
    Registered User
    Join Date
    12-11-2023
    Location
    los altos, ca
    MS-Off Ver
    2016
    Posts
    38

    Re: VBA to update Sheet 2 the Location from Sheet 1. Thank you very much

    Hi John

    Hope you have another easy day
    Thank you so much John for always helping people. Your time & knowledge are greatly appreciated.
    I forgot to mention that Sheet1 is actually one of the 6 Sheets (>300,000) that originallly downloaded from the database. Let's call it File 1
    In the other word, my job is download the 300,000 records into Excel that comes with 6 sheets together
    I have to compare with another file with about 3,000 records. Let's call it File 2.
    File 1 & File 2 has different numbers of headings (as the original attached sample) with 2 common headings Client ID, Location.
    I need to update the Location of File 2 from File 1 for the matching Client ID

    So instead of compare the 2 Sheets (Sheet 1 to Sheet 2), now compare 6 Sheets (File 1 with >300,000 files) to Sheet7 (File 2 >3,000 records, smaller file)

    Thanks a lot again John.
    I will post it the new one.

  6. #6
    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,317

    Re: VBA to update Sheet 2 the Location from Sheet 1. Thank you very much

    I forgot to mention that Sheet1 is actually one of the 6 Sheets (>300,000 files [.. rows in TOTAL?])
    ... somewhat of an "oversight" !

    Please post sample files as this is likely to require a VBA rather than a simple formula solution.

    And remove "SOLVED" from thread as others may address the problem.
    Last edited by JohnTopley; 03-14-2024 at 06:18 AM.

  7. #7
    Registered User
    Join Date
    12-11-2023
    Location
    los altos, ca
    MS-Off Ver
    2016
    Posts
    38

    VBA to update Sheet 2 the Location from Sheet 1. Thank you very much

    Hi Super Coders

    Hope you have a great new week.
    I urgently need your talent please.

    Attached are 2 Excel files with different numbers of Column Headings.
    However, both have 2 common Column Headings: ClientID (Primary Key) & Location.
    The number of Column Headings in both File 1 and File 2 could be changing more over time.

    File 1 (>300,000 records) - downloaded file that comes with 6 Protected Sheets which contain the Location data that File 2 needs.
    File 2 (>3,000 records) - where The column named Location needs to be UPDATED.

    My job is to update column Location of File 2 for the matching Client ID.


    Thank you so much for your time & help
    Attached Images Attached Images
    Attached Files Attached Files

  8. #8
    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,317

    Re: VBA to update Sheet 2 the Location from Sheet 1. Thank you very much

    Please Login or Register  to view this content.
    Assumes "File 1" is open.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    12-11-2023
    Location
    los altos, ca
    MS-Off Ver
    2016
    Posts
    38

    Re: VBA to update Sheet 2 the Location from Sheet 1. Thank you very much

    Hi John
    Ali requested me not to repost as new thread. So I modify the old post. Hopefully, you see the OLD post with additional info.
    Hope you have another wonderful day John.
    Thanks a lot for your time & kind, quick help.

  10. #10
    Registered User
    Join Date
    12-11-2023
    Location
    los altos, ca
    MS-Off Ver
    2016
    Posts
    38

    Re: VBA to update Sheet 2 the Location from Sheet 1. Thank you very much

    *********THANKS MILLIONS JohnTopley for your SUPER POWERFUL, QUICK CODES. You're Super Genius. Thanks a lot for your time & talent. I wish I could add millions stars to reputation. BIG THANKS JOHN TOPLEY******
    I tried to add reputation but the message says You can't add reputation to the same post twice.
    John, I can't thank you enough for keeping helping people. You're such great gifted coder. God bless !

  11. #11
    Registered User
    Join Date
    12-11-2023
    Location
    los altos, ca
    MS-Off Ver
    2016
    Posts
    38

    Re: VBA to update Sheet 2 the Location from Sheet 1. Thank you very much

    Hi John
    Hope you are well.
    My File 1, File 2 have changed in total columns. I tried to figure out with the codes but it did not work for me. Your code is miracle but when the total of columns change, I dont know what part of the code i should modify. I tried to change 6 to 5 because of the Total Sheets had changed.
    Could you please kindly help me? thanks a lot. I attached the

  12. #12
    Registered User
    Join Date
    12-11-2023
    Location
    los altos, ca
    MS-Off Ver
    2016
    Posts
    38

    Re: VBA to update Sheet 2 the Location from Sheet 1. Thank you very much

    Hi John
    Hope you are well. I am testing the email

  13. #13
    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,317

    Re: VBA to update Sheet 2 the Location from Sheet 1. Thank you very much

    I can't do anything without seeing the files.

  14. #14
    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,317

    Re: VBA to update Sheet 2 the Location from Sheet 1. Thank you very much

    If number of sheets in "File 2" has changed then amend code as:

    Please Login or Register  to view this content.
    For anything else, post files.

  15. #15
    Registered User
    Join Date
    12-11-2023
    Location
    los altos, ca
    MS-Off Ver
    2016
    Posts
    38

    Re: VBA to update Sheet 2 the Location from Sheet 1. Thank you very much

    Hi John

    Thank you so much again for your kind, quick help as always. I have your code modified as instructed but received run-time error pointing at:
    dic.Add Key:=str, Item:=b(j, loc2)
    Files attached.

    How could I fix this?
    Thanks a lot
    Attached Files Attached Files
    Last edited by jojo4santa; 03-19-2024 at 06:09 AM.

  16. #16
    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,317

    Re: VBA to update Sheet 2 the Location from Sheet 1. Thank you very much

    Please Login or Register  to view this content.
    Problem caused by heading blank entries in row 1 of "File 1"

    And there was an error in the code!
    Attached Files Attached Files
    Last edited by JohnTopley; 03-19-2024 at 06:36 AM.

  17. #17
    Registered User
    Join Date
    12-11-2023
    Location
    los altos, ca
    MS-Off Ver
    2016
    Posts
    38

    Re: VBA to update Sheet 2 the Location from Sheet 1. Thank you very much

    Thanks millions for your super quick help again John. Your modified code works like a MIRACLE. I tried to add reputation to your hard work but receive the message "You must spread some Reputation around before giving it to JohnTopley again."
    Wishing you a wonderful, prosperous week. God bless you!

  18. #18
    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,317

    Re: VBA to update Sheet 2 the Location from Sheet 1. Thank you very much

    Glad to know all is O.K.

  19. #19
    Registered User
    Join Date
    12-11-2023
    Location
    los altos, ca
    MS-Off Ver
    2016
    Posts
    38

    Re: VBA to update Sheet 2 the Location from Sheet 1. Thank you very much

    Hi John

    Hope you are well.
    Your code for the 2 files sample work like miracle BECAUSE file 1 sample is small.
    However, in reality my File 1.xlsx > 300,000 records (in protected view with 5 Sheets after downloaded from our server) and the code could not work.
    Do you know any solution to make the code work for the large file?

    Thank you so much John
    Attached Files Attached Files
    Last edited by jojo4santa; 04-20-2024 at 10:45 PM.

  20. #20
    Registered User
    Join Date
    12-11-2023
    Location
    los altos, ca
    MS-Off Ver
    2016
    Posts
    38

    Re: VBA to update Sheet 2 the Location from Sheet 1. Thank you very much

    Hi John

    Hope you are well.
    Your code is such a miracle. However, I have difficulty as my file has 5 sheets with >300,000 records. Each sheet contains 65528 records and everytime, the code can't be executed. I had to cut down the records. Is there a better way John?
    Thanks a lot for your time & kind help as always

  21. #21
    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,317

    Re: VBA to update Sheet 2 the Location from Sheet 1. Thank you very much

    the code can't be executed
    .... meaning it takes a long time to execute?

    The key issue here (I think!) is the number of clients: the macro uses Scripting Dictionary, which in my limited experience of using, is not very effecient when there are many "keys" i.e clients in this case.

    How many unique clients are there? From your intitial post, just over 3000 (?)

    Question: why are we searching through 300,000 records each time when the 3000+ clients are going to be relative static ???

    Please post a file with (at least) one sheet with a large number of rows.
    Last edited by JohnTopley; 04-09-2024 at 11:01 AM.

  22. #22
    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,317

    Re: VBA to update Sheet 2 the Location from Sheet 1. Thank you very much

    A different approach:

    The Client ID and Location from each sheet in "File 1" is copied to sheet "Temp" in "File 2 V2". Duplicate "Client ID" are removed, sorted by "Cllent ID" and added to "Scripting Dictionary" which is then used to populate Sheet1 in "File 2 V2".

    Please try this and let me know the result

    Still happy to test with a large file if required.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by JohnTopley; 04-09-2024 at 12:12 PM.

  23. #23
    Registered User
    Join Date
    12-11-2023
    Location
    los altos, ca
    MS-Off Ver
    2016
    Posts
    38

    Re: VBA to update Sheet 2 the Location from Sheet 1. Thank you very much

    Hi Super Genius John

    Thank you so much again for your SUPER POWERFUL CODES. I have tested your codes on the files with > 300,000 records (this is growing every single hour). Both Module1, Module2 codes are working PERFECTLY LIKE MIRACLES. You can't imagine how you dry up my tears each day.
    Both Files come with different Headings, Total of Columns, Total of Records. File 2 (close to 40,000 records) & File 1 (>300,000 records) that I download from server. However, both Files have 2 Identical Columns with the Headings (ClientID & Location)
    My job is updating the Location from File 1 to Location in File 2.
    Now with your miracles, my nightmare job turns to heaven. Thank you millions for your kindness for always quickly helping me. May God bless you and yours John. Thanks a lot. I just added millions * to your reputation. YOu're the BEST!!!
    Last edited by jojo4santa; 04-10-2024 at 01:11 PM.

  24. #24
    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,317

    Re: VBA to update Sheet 2 the Location from Sheet 1. Thank you very much

    Glad everything is now OK. Thank you for the rep.

  25. #25
    Registered User
    Join Date
    12-11-2023
    Location
    los altos, ca
    MS-Off Ver
    2016
    Posts
    38

    Re: VBA to update Sheet 2 the Location from Sheet 1. Thank you very much

    Hi John

    I hope you have a restful weekend.
    You have helped me with the powerful code.
    However, our users entered data in the wrong column. Data should be entered in Location found in column Employee.
    Could you please kindly help me add in your previous code with additional lines.

    We have 2 Excel Files. Both have different headings but have 2 same columns : Column ClientID (Primary key) & Location.
    File 1.xlsx (>3000,000 records) with 5 Sheets with 3 important Headings: ClientID, Location, Employee.
    File 2.xlsm - 1 Sheet only

    What I need the program to do is :

    Copy all Location from File 1 to File 2 once ClientID matches.
    If Location is blank then copy data from column Employee instead.
    I attach the 2 files again with your previous working codes.

    Thanks a lot again John
    Attached Files Attached Files
    Last edited by jojo4santa; 04-20-2024 at 11:09 PM.

  26. #26
    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,317

    Re: VBA to update Sheet 2 the Location from Sheet 1. Thank you very much

    Please Login or Register  to view this content.
    Output in sheet "TEMP" in "File 1" but equally could update the sheets 1:5.
    Attached Files Attached Files

  27. #27
    Registered User
    Join Date
    12-11-2023
    Location
    los altos, ca
    MS-Off Ver
    2016
    Posts
    38

    Re: VBA to update Sheet 2 the Location from Sheet 1. Thank you very much

    Hi John

    I wish your day goes well.
    I stayed up late last night trying to figure out how to run your code.
    Attached are the 2 Excel Files & the screen shot of the BEFORE & AFTER running your previous miraculous code.

    My task is filling in the Location for the ClientIDs in File 2.
    As you can see from the attached. Both Files have different Column Headings but have the same 2 Headings Columns which are ClientID & Location.

    File 1 - has 5 Sheets with > 300,000 records.
    File 2 - has only 1 Sheet with approximately 40,000 records.

    ------Please try to run your previous code in File 2 attached. It works perfect.
    However, the Location of ClientID #4 is left blank due to users' data entry errors. Instead of entering data in the Location, they entered it into Employee.
    Is it possible if you can edit your previous PERFECT code (attached in File 2) that when Location is blank, copy data from Employee into Location in File 2?
    We are only interested in obtaining finding the Location for the MATCHING ClientIDs in File 2 - which are ClientIDs: 1, 2, 3, 4, 5 hilited yellow.
    FILE 2 is the File we need to complete the missing data for Location.
    File 1 is where the data extracted from for the Location in File 2 once ClientID matches. Only the Location for Yellow hilted ClientIDs are needed to be filled.


    Thank you so much again for your kind help
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by jojo4santa; 04-22-2024 at 09:18 PM.

  28. #28
    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,317

    Re: VBA to update Sheet 2 the Location from Sheet 1. Thank you very much

    Please Login or Register  to view this content.
    Writes data for "File 2": both files open.
    Attached Files Attached Files

  29. #29
    Registered User
    Join Date
    12-11-2023
    Location
    los altos, ca
    MS-Off Ver
    2016
    Posts
    38

    Re: VBA to update Sheet 2 the Location from Sheet 1. Thank you very much

    Hi John

    I added your reputation for your quick 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: 3
    Last Post: 04-16-2020, 07:43 PM
  2. [SOLVED] Grabbing data from one sheet and moving it to a specific location in another sheet
    By BlackenedEDIT in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-01-2020, 02:56 PM
  3. Search the location & automatic paste date from one sheet to another master sheet.
    By Mofasol in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-29-2017, 09:58 AM
  4. [SOLVED] Update Values: Location Sheet
    By skellz022782 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-29-2016, 11:33 AM
  5. Need to update location & Rep names based on data availabe in sheet "details"
    By aleanboy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-06-2014, 04:35 PM
  6. Replies: 3
    Last Post: 01-17-2014, 11:51 PM
  7. Exporting and saving a sheet to a user defined location? (Archiving a sheet)
    By JamesGoulding85 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-19-2013, 07:25 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