+ Reply to Thread
Results 1 to 42 of 42

VBA for merge files from a location and pulling data based on a criteria

  1. #1
    Forum Contributor Neilesh Kumar's Avatar
    Join Date
    05-26-2016
    Location
    INDIA
    MS-Off Ver
    2013 & 2016
    Posts
    848

    VBA for merge files from a location and pulling data based on a criteria

    Dear Experts,

    I have a folder (Location: C:\Users\Neilesh\Documents\Destop Files\Recon\Daily Working Recon\2023\04 Apr 2023) and under 04 Apr 2023 folder I have created Daily Recon Excel files for April 2023, based on each day until now as name 04.01.2023 Recon, 04.02.2023 Recon, 04.03.2023 Recon, 04.04.2023 Recon, and so on.

    Please find here attached a sample workbook, where I am expecting to pull all the lines from the Open Item tab from all the folder workbooks except the highlighted comments in column X by creating a single workbook. So the highlighted comments are repeating in all the workbook and with the help VBA I am expecting to get all the values from column A until column X from the Open Item tab and from all the workbooks which will copy and paste all the data and creates a single workbook from column A until column X except the highlighted comments in column X.

    After getting the expected outcome as merged files except the highlighted cell values we expect to save the file automatically at C:\Users\Neilesh\Documents\Destop Files as "Merged file Apr 2023". I want to use the VBA for the upcoming months to merge the files and create one file. So while working on May 2023 recons the main location path will be C:\Users\Neilesh\Documents\Destop Files\Recon\Daily Working Recon\2023\05 Apr 2023 and the working file names would be 05.01.2023 Recon, 05.02.2023 Recon, 05.03.2023 Recon and so on.

    Please feel free to revert and request you to please help me on the same. Thank you in advance.

    Regards,

    Neilesh
    Attached Files Attached Files
    Last edited by Neilesh Kumar; 04-23-2023 at 12:37 PM.

  2. #2
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: VBA for merge files from a location and pulling data based on a criteria

    When you say you don't want to copy the highlighted text, does that mean you don't want the cell value in X not copied over or you don't want that whole row, A to X, not copied over?

  3. #3
    Forum Contributor Neilesh Kumar's Avatar
    Join Date
    05-26-2016
    Location
    INDIA
    MS-Off Ver
    2013 & 2016
    Posts
    848

    Re: VBA for merge files from a location and pulling data based on a criteria

    Dear Sir,

    We need the complete rows data from column A to X except the highlighted cells values in column X so while running the script we expect to exclude the rows from column A to X based on column X highlighted values. Currently, i have provided the data for the current month so the same process will continue for upcoming months.

    I have highlighted column X values manually so we expect to filter column X values and exclude the complete row based on highlighted values in column X and not by color.

    Hope i have clarified now. Please feel free to revert if there is any further clarification if required. Thank you!!!

    Regards,

    Neilesh

  4. #4
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: VBA for merge files from a location and pulling data based on a criteria

    In this process, the code asks to select the folder with the files you want processed. The code will process all the files in that directory as long as the name of the file has the same month in the name. Here is the code.

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor Neilesh Kumar's Avatar
    Join Date
    05-26-2016
    Location
    INDIA
    MS-Off Ver
    2013 & 2016
    Posts
    848

    Re: VBA for merge files from a location and pulling data based on a criteria

    Dear Manicab expert, Provided script are merging the workbooks but challenge is still there with filters. It is not exluding the below lines from column X wherever these value appears.

    1) Blended item variance due to disposition on contract; should clear at month end when earnings are ran in Infolease
    2) New write-down in the current month, the blended items income/tax method was flipped to “FLOW” thru the nightly bash and the unearned blended net investment will flush to the P&L at month end when earnings are ran which will clear this recon variance
    3) Prior partial writedown now has $0 net investment so writedown UDF has been fixed to “F” by EOT, unearned blended items will be accelerated by Infolease at month end when income job is run as blended income method is being bashed to change to “FLOW” on “F
    4) Stat SSR file is only sent once on close day 1 for month end balances, due to the way OBIEE V4 works if Infolease does not send a Stat file daily the Stat CAAS will show as a variance on BD1 – BD5 of current month recon until BD5 when the reversing Stat file is sent (GL is correct but sub system shows as $0 because OBIEE overrides sub-system to $0 since no daily Stat GL feed is sent from IL to ledger on BD1 - BD4, month end final recon had no stat variance so this is not a "real" variance, only concerned with Stat variances after BD5 SSR recon)
    5) Pending enhancement #98165 Write-down NLC Offset
    6) Disposed prior write-down, finance income recovery already previously recognized need to reverse gain on term
    7) Deleted OLCB Renewal
    8) Contract number change assumption
    9) Defect 6837 CB Renewal in Nonaccrual Offset
    10) Defect 9085 OLCB Renewal Booking Nonaccrual Offset
    11) Disposition Reversal, NLC manually re-built by Operations, offsetting entry needed to equipment funding GL account
    12) Payment posted on writedown contract, belongs to finance income recovery that needs re-classed topside

    So we need to exclude all the rows based on the above 12 values if they appears in column X. Can you please help me on the same. Thank you!!!

    Regards,

    Neilesh

  6. #6
    Forum Contributor Neilesh Kumar's Avatar
    Join Date
    05-26-2016
    Location
    INDIA
    MS-Off Ver
    2013 & 2016
    Posts
    848

    Re: VBA for merge files from a location and pulling data based on a criteria

    I have highlighted rows manually to identify the excluding items but every time we will not be in a position to highlight the excluding items from each workbook.

  7. #7
    Forum Contributor Neilesh Kumar's Avatar
    Join Date
    05-26-2016
    Location
    INDIA
    MS-Off Ver
    2013 & 2016
    Posts
    848

    Re: VBA for merge files from a location and pulling data based on a criteria

    or is it possible if we create a new tab for excluding the lines and paste these 12 excluding criterias in that tab and based on the list script filter and provide us the output. This will also do for me.

  8. #8
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: VBA for merge files from a location and pulling data based on a criteria

    Placing these items in a tab is the best solution. I’ll update code to look for these items and exclude lines with them in them.

  9. #9
    Forum Contributor Neilesh Kumar's Avatar
    Join Date
    05-26-2016
    Location
    INDIA
    MS-Off Ver
    2013 & 2016
    Posts
    848

    Re: VBA for merge files from a location and pulling data based on a criteria

    Thank you so much dear expert. I need to add one more expectation from the output file that we need to also extract the outcome with unique values from column A. If the column value repeats then we need to extract only the first line. Request you to please help me. Thank you!!!

    Regards,

    Neilesh
    Last edited by Neilesh Kumar; 04-24-2023 at 12:54 PM.

  10. #10
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: VBA for merge files from a location and pulling data based on a criteria

    Here are the updates you requested. I'm also including the file so you can start using the Exclude tab and update that as you need. I am using the text in Column A of the Open Item tab to exclude duplicates.

    Please Login or Register  to view this content.

  11. #11
    Forum Contributor Neilesh Kumar's Avatar
    Join Date
    05-26-2016
    Location
    INDIA
    MS-Off Ver
    2013 & 2016
    Posts
    848

    Re: VBA for merge files from a location and pulling data based on a criteria

    Dear Expert maniacb, While running the script, I am facing the script error "Invalid procedure call or argument 5". Can you please look into the same and fix. Thank you!!!

  12. #12
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: VBA for merge files from a location and pulling data based on a criteria

    When I run the script, I can not duplicate the error. Please let me know which line is highlighted with the error. Place an asterisk on the far left of line "On Error GoTo Trap" so it looks like "'On Error GoTo Trap" without the quotes. This will turn off the error trapping and allow you to see what line errors out.

  13. #13
    Forum Contributor Neilesh Kumar's Avatar
    Join Date
    05-26-2016
    Location
    INDIA
    MS-Off Ver
    2013 & 2016
    Posts
    848

    Re: VBA for merge files from a location and pulling data based on a criteria

    Hi Maniacb, Sorry for the delayed reply as i was on official trip. I am facing challenges from Ln 37 col 20 till Ln 40 col 17. after Ln 40 col 17 the script jumping back to Ln 37 col 20.

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

    Re: VBA for merge files from a location and pulling data based on a criteria

    Quote Originally Posted by Neilesh Kumar View Post
    I have a folder (Location: C:\Users\Neilesh\Documents\Destop Files\Recon\Daily Working Recon\2023\04 Apr 2023) and under 04 Apr 2023 folder I have created Daily Recon Excel files for April 2023, based on each day until now as name 04.01.2023 Recon, 04.02.2023 Recon, 04.03.2023 Recon, 04.04.2023 Recon, and so on.

    After getting the expected outcome as merged files except the highlighted cell values we expect to save the file automatically at C:\Users\Neilesh\Documents\Destop Files as "Merged file Apr 2023".
    try
    Please Login or Register  to view this content.

  15. #15
    Forum Contributor Neilesh Kumar's Avatar
    Join Date
    05-26-2016
    Location
    INDIA
    MS-Off Ver
    2013 & 2016
    Posts
    848

    Re: VBA for merge files from a location and pulling data based on a criteria

    Dear expert Jindon. Thank you. Let me please try and will revert you shortly. Thank you once again.
    Last edited by Neilesh Kumar; 04-29-2023 at 01:23 PM.

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

    Re: VBA for merge files from a location and pulling data based on a criteria

    If the folder is located on network, try replace "test" with the below while "Function GetList()" should be kept intact.
    Please Login or Register  to view this content.

  17. #17
    Forum Contributor Neilesh Kumar's Avatar
    Join Date
    05-26-2016
    Location
    INDIA
    MS-Off Ver
    2013 & 2016
    Posts
    848

    Re: VBA for merge files from a location and pulling data based on a criteria

    Dear Expert Jindon, Just wanted to confirm that do i need to use Function Getlist () script with updated script or not because with updated script i am getting error for network folder as "Folder not found" and with Function GetList() getting error for Ln8, Col 28. Please confirm. Thank you!!!

    or is it possible instead of putting directory in the script can we add a script where it will ask to select manually for Directory and Merging files as well?
    Last edited by Neilesh Kumar; 04-30-2023 at 01:31 PM.

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

    Re: VBA for merge files from a location and pulling data based on a criteria

    Then copy the files onto your local folder.
    And the function must be kept as it is.

  19. #19
    Forum Contributor Neilesh Kumar's Avatar
    Join Date
    05-26-2016
    Location
    INDIA
    MS-Off Ver
    2013 & 2016
    Posts
    848

    Re: VBA for merge files from a location and pulling data based on a criteria

    Sure Dear expert let me try by running the script by copying the files onto local folder. Thank you

  20. #20
    Forum Contributor Neilesh Kumar's Avatar
    Join Date
    05-26-2016
    Location
    INDIA
    MS-Off Ver
    2013 & 2016
    Posts
    848

    Re: VBA for merge files from a location and pulling data based on a criteria

    Dear Expert Jindon, I have copied the data on the desktop and tried to use the below script but getting an error message as folder not found. Can you please look into the same and let me know whether I am running the correct script or not? Thank you!!!

    So "04 Apr" is the folder where I have saved all my excel files on the Desktop.

    Please Login or Register  to view this content.
    Last edited by Neilesh Kumar; 05-01-2023 at 11:09 AM.

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

    Re: VBA for merge files from a location and pulling data based on a criteria

    Please Login or Register  to view this content.
    Don't change any line, just use my original code in #14.
    Last edited by jindon; 05-02-2023 at 03:27 AM.

  22. #22
    Forum Contributor Neilesh Kumar's Avatar
    Join Date
    05-26-2016
    Location
    INDIA
    MS-Off Ver
    2013 & 2016
    Posts
    848

    Re: VBA for merge files from a location and pulling data based on a criteria

    Dear Expert Jindon, The reason to change the path is that I have saved all folders and files at the Desktop location results I had to change the path but with the current path "C:\Users\Neilesh\Desktop\04 Apr", I am unable to fetch the required data. Please let me know if you still want me use the same path or want me to continue with "C:\Users\Neilesh\Desktop\04 Apr" path. Thank you!!!
    Last edited by Neilesh Kumar; 05-02-2023 at 10:40 AM.

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

    Re: VBA for merge files from a location and pulling data based on a criteria

    Still confusing,

    You have 2023 folder on Desk Top.
    2023 has subfolder named 04 Apr.
    04 Apr has daily files.

    Please Login or Register  to view this content.
    Last edited by jindon; 05-03-2023 at 09:38 PM.

  24. #24
    Forum Contributor Neilesh Kumar's Avatar
    Join Date
    05-26-2016
    Location
    INDIA
    MS-Off Ver
    2013 & 2016
    Posts
    848

    Re: VBA for merge files from a location and pulling data based on a criteria

    Dear Expert Jindon, Now it has started working but getting debug at "If i = 19 Then Stop" after processing the first two days of files. My all Excel files are in "mm.dd.yyyy Recon" format so can you please help me with the same.

    I have nothing changed with the script and using it exactly as it is. Request you to please help me dear expert jindon. Thank you once again.

    Would like to update that for Saturday and Sunday or if there is any holiday we are not preparing recons during the month. So there will be missing dates with the recon files in 04 Apr folder but for the working days we are preparing the files and saving under 04 Apr folder as "mm.dd.yyyy Recon" for April Month so if we are in May then we will create a folder under 2023 as 05 May and save all the daily recons under the same.

    Regards,

    Neilesh
    Last edited by Neilesh Kumar; 05-03-2023 at 01:56 PM.

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

    Re: VBA for merge files from a location and pulling data based on a criteria

    1) Just delete that line.(code in #23 edited)
    2) once you created the Merged File for 04, change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  26. #26
    Forum Contributor Neilesh Kumar's Avatar
    Join Date
    05-26-2016
    Location
    INDIA
    MS-Off Ver
    2013 & 2016
    Posts
    848

    Re: VBA for merge files from a location and pulling data based on a criteria

    Dear Expert, When we are trying to run the script in the May month for the 04 Apr folder it is allowing us to run the script. Every time I need to rename the folder with the current month if I need to run for the previous month.

    So i thought to whichever folder I need to run the script I will simply copy the script file and run the script from the folder but it is not allowing me to do so if I am renaming the folder in May month as 05 May with April workbooks then it does not give any outcome and only with blank workbook.
    Last edited by Neilesh Kumar; 05-04-2023 at 05:51 AM.

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

    Re: VBA for merge files from a location and pulling data based on a criteria

    You must tell me when you run the code for what month?
    The code creates for current month, so it only deal with 05 May if you run in May.

  28. #28
    Forum Contributor Neilesh Kumar's Avatar
    Join Date
    05-26-2016
    Location
    INDIA
    MS-Off Ver
    2013 & 2016
    Posts
    848

    Re: VBA for merge files from a location and pulling data based on a criteria

    so i can not run the script for April month in May?

  29. #29
    Forum Contributor Neilesh Kumar's Avatar
    Join Date
    05-26-2016
    Location
    INDIA
    MS-Off Ver
    2013 & 2016
    Posts
    848

    Re: VBA for merge files from a location and pulling data based on a criteria

    Can you please update the script in such a way that will ask everytime to select the folder before filter and giving the outcome so that for any period i can merge the file. That would be really helpful for me.
    Last edited by Neilesh Kumar; 05-04-2023 at 05:59 AM.

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

    Re: VBA for merge files from a location and pulling data based on a criteria

    If you always run for the previous month then change to
    Please Login or Register  to view this content.

  31. #31
    Forum Contributor Neilesh Kumar's Avatar
    Join Date
    05-26-2016
    Location
    INDIA
    MS-Off Ver
    2013 & 2016
    Posts
    848

    Re: VBA for merge files from a location and pulling data based on a criteria

    Dear Expert Jindon, i have tried but still the outcome is with blank workbook. Please find here attached few sample recon workbooks and provided script for testing. Please create a folder at Desktop as 2023 under 2023 folder please creat 04 Apr folder and under 04 Apr folder please save these sample workbooks and try running the script which is giving blank workbook as outcome.

    Regards,

    Neielsh
    Attached Files Attached Files

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

    Re: VBA for merge files from a location and pulling data based on a criteria

    Why are you changing code the and the files?

    This is my last warning.
    If you think you are able to adjust the code, do it for yourself.

  33. #33
    Forum Contributor Neilesh Kumar's Avatar
    Join Date
    05-26-2016
    Location
    INDIA
    MS-Off Ver
    2013 & 2016
    Posts
    848

    Re: VBA for merge files from a location and pulling data based on a criteria

    Dear Expert, I haven't changed the files, and based on the system I am currently using I had to change the location path for the folder so I have changed.

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

    Re: VBA for merge files from a location and pulling data based on a criteria

    Why did you change to
    Please Login or Register  to view this content.
    ?

    What is your intention?


    And why sheet name in 04.28.2023 Recon.xlsx is Open Items?
    Last edited by jindon; 05-04-2023 at 09:24 AM.

  35. #35
    Forum Contributor Neilesh Kumar's Avatar
    Join Date
    05-26-2016
    Location
    INDIA
    MS-Off Ver
    2013 & 2016
    Posts
    848

    Re: VBA for merge files from a location and pulling data based on a criteria

    Dear Expert, my intention is only to get the results based on script so when it was not giving the outcome then i tried by changing the names in the script as well changing the file names but then also it has not provided the outcome so requested to help.

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

    Re: VBA for merge files from a location and pulling data based on a criteria

    Use the code in post #23 and change one line as I mentioned in post #30, so that the code always look for previous month folder.

    Open attached and place the folder 2023 onto your desk top and run the code.
    Merge file will be created on desk top.
    Attached Files Attached Files

  37. #37
    Forum Contributor Neilesh Kumar's Avatar
    Join Date
    05-26-2016
    Location
    INDIA
    MS-Off Ver
    2013 & 2016
    Posts
    848

    Re: VBA for merge files from a location and pulling data based on a criteria

    Dear Expert Jindon, Script is working but the only challenge is with the spreadsheet which is getting created as completely blank so after running the script the new workbook is getting created and save on the desktop which is completely blank.

  38. #38
    Forum Contributor Neilesh Kumar's Avatar
    Join Date
    05-26-2016
    Location
    INDIA
    MS-Off Ver
    2013 & 2016
    Posts
    848

    Re: VBA for merge files from a location and pulling data based on a criteria

    Please try running with the provided VBA script as attached.
    Attached Files Attached Files

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

    Re: VBA for merge files from a location and pulling data based on a criteria

    Hopeles...
    I said
    Quote Originally Posted by jindon View Post
    Use the code in post #23 and change one line as I mentioned in post #30, so that the code always look for previous month folder.
    Please Login or Register  to view this content.

  40. #40
    Forum Contributor Neilesh Kumar's Avatar
    Join Date
    05-26-2016
    Location
    INDIA
    MS-Off Ver
    2013 & 2016
    Posts
    848

    Re: VBA for merge files from a location and pulling data based on a criteria

    Dear Expert Jindon, Thank you so much it is giving the expected outcome so one last request i have suppose if need to run the script for 01 Jan folder then will the provided script work or not and if not then can you please provide your expertise on the same. Thank you once again and apologies for bothering you.

    I am really sorry for bothering you a lot.
    Last edited by Neilesh Kumar; 05-04-2023 at 11:06 AM.

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

    Re: VBA for merge files from a location and pulling data based on a criteria

    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    Set back to Date - Day(Date)

  42. #42
    Forum Contributor Neilesh Kumar's Avatar
    Join Date
    05-26-2016
    Location
    INDIA
    MS-Off Ver
    2013 & 2016
    Posts
    848

    Re: VBA for merge files from a location and pulling data based on a criteria

    Thank you so much Dear Expert Jindon and apologies for bothering a lot. Once again thank you so much.

+ 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. [SOLVED] Pulling Data Based on Criteria from One List to Another
    By tispivey in forum Excel Formulas & Functions
    Replies: 25
    Last Post: 03-04-2022, 04:50 AM
  2. Merge two text files with given file location in Sheet1
    By vikim in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-24-2021, 11:56 AM
  3. Move Multiple Files into Specific Location Based On Criteria
    By ShakJames in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 12-14-2018, 08:44 AM
  4. VBA Merge Files: Location Path as cell reference
    By kalyan46 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-31-2018, 11:16 AM
  5. Replies: 2
    Last Post: 10-16-2016, 11:08 PM
  6. [SOLVED] pulling data based on criteria
    By keith740 in forum Excel General
    Replies: 3
    Last Post: 08-16-2015, 04:36 PM
  7. Replies: 2
    Last Post: 02-27-2009, 02:01 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