+ Reply to Thread
Results 1 to 6 of 6

VBA code modification to copy data from a folder when name matches

  1. #1
    Registered User
    Join Date
    09-11-2019
    Location
    india
    MS-Off Ver
    2016
    Posts
    78

    VBA code modification to copy data from a folder when name matches

    Hi Experts,
    Hope you all are safe and doing good.

    I need a heling hand making my code more dynamic so that I do not have to click and choose files one by one.

    I have a folder where I place multiple reports . I also have a Master sheet, where I have my code and want to copy data to the sheet name "Data" in my master sheet from the other files placed in that folder.

    Lets say I have a Report named as "Query" placed in the folder. I will run the VBA and when filename = Query, then it will copy data from that report and paste it in Master workbook sheet "Data".

    Please note all the reports placed in folder will have only 1 sheet, but the names might not be the same. So we can take the sheet number instead so that I do not have to be worried about the names.

    So my goal is, if I have 5 files then i should just click the macro only once and the it will search for the file name, if matches copy the data and paste.

    Please Login or Register  to view this content.

  2. #2
    Registered User
    Join Date
    09-11-2019
    Location
    india
    MS-Off Ver
    2016
    Posts
    78

    Re: VBA code modification to copy data from a folder when name matches

    Can someone please help me on this ?

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: VBA code modification to copy data from a folder when name matches

    Try something like this. Change the path and base file name "*Query*" to suit.

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  4. #4
    Registered User
    Join Date
    09-11-2019
    Location
    india
    MS-Off Ver
    2016
    Posts
    78
    Quote Originally Posted by AlphaFrog View Post
    Try something like this. Change the path and base file name "*Query*" to suit.

    Please Login or Register  to view this content.
    Thanks a lot AlphaFrog for your help. I am yet to try the code,but the only thing what I see here is I have to give the folder path. And if somebody else wants to use this macro sheet then the folder path has to be provided again. So want keep it more dynamic so that use can select their own folders. Any suggestions with this? And how do I add multiple files ? So when the name match query and macro does its work should move to the next file and do it's work

  5. #5
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: VBA code modification to copy data from a folder when name matches

    No need to quote my code.

    Below will prompt the user to select a folder and then loop through all the files in that folder that contain "query" in the file name.

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    09-11-2019
    Location
    india
    MS-Off Ver
    2016
    Posts
    78

    Re: VBA code modification to copy data from a folder when name matches

    Hi AlphaFrog ,
    Thanks and sorry for the quote (I replied from my moblie )

    I tried the new code now, but it copied data and placed from 16th row and not from the 1st row

+ 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. Copy till last - we have vba code, just required a modification
    By Ajay45822 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-09-2021, 12:50 PM
  2. [SOLVED] Copy files of a certain file name length, extension & modification date to another folder
    By JET2011 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-25-2018, 02:38 PM
  3. Assign Hyperlink to cell if data matches files from a folder/sub folder
    By f_htn in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-21-2018, 04:03 PM
  4. Loop through folders and execute code if folder name matches specified names
    By hopeful_positive in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-20-2018, 04:40 AM
  5. Loop through folders and only implement code if folder name matches from specified names
    By hopeful_positive in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-19-2018, 11:46 AM
  6. [SOLVED] VBA Code open files in folder, copy text to workbook-Next time folder opened copy only new
    By Bikeman in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-02-2013, 07:59 PM
  7. Need Help Fixing Code to Copy Data From Files in a Folder
    By latausm in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-08-2011, 12:06 PM

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