+ Reply to Thread
Results 1 to 14 of 14

Macro Search tool for File Explorer in Folders/ Subsolders - more userfriendly

  1. #1
    Registered User
    Join Date
    02-05-2025
    Location
    BELGIUM
    MS-Off Ver
    EXCEL
    Posts
    7

    Lightbulb Macro Search tool for File Explorer in Folders/ Subsolders - more userfriendly

    Hello,

    As I work with data, sometimes i need to search 1 specific record or a word in a cell.
    I recently found a Marco that search a *word* in multiple Excel files in a specific File folder.
    This save me a lot of time opening each individual XLSX file and use the CTRL+F (find function).

    But it isn't that user friendly, U have to open VBA before u run it and change the 'search word' manually.
    All the cells that contains that word are returned then with the file names and the specific cell adresses.


    What i would like is, that if u run the macro:
    1) u get a pop up where u have to type in the word to find.
    + Hit a button that says 'search'
    2)then u have to choose a File Folder where the macro/search has to be run (this is already implemented).
    But the macro doesn't search in subfolders, i don't know if this is possible.

    *note* that im not an experienced user of VBA and Macro applications in EXCEL;
    I can get the bigger picture, but the details are not my kind of expertise.

    It would be great if i got some advice how to make these changes !!

    Thanks in advance!!

    Example file:

    I've added a simple example:
    So if go to step into macro, i adapt the search string, here now KIWI27.
    and hit RUN, the macro opens a file explorer screen where i can select the designated folder, where a multiple workbooks saved.
    The Macro will look in each Workbook searching for the string.
    All the result are than stored and shown in a new sheet. (see sheet2)

    Like mentioned, i would like a pop up box where i can add the search string, then hit ok, then the designated folder must be selected.
    the result that are created in a new sheet is fine for me.

    the code is as follows:

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by YDE98; 02-05-2025 at 08:42 AM.

  2. #2
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,964

    Re: Macro Search tool for File Explorer in Folders/ Subsolders - more userfriendly

    Hi there YDE98...
    Welcome to the forum...
    Can you give us an idea of how the setup of these files look...Perhaps upload a sample of 1...
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  3. #3
    Registered User
    Join Date
    12-05-2023
    Location
    France
    MS-Off Ver
    Office 365
    Posts
    12

    Re: Macro Search tool for File Explorer in Folders/ Subsolders - more userfriendly

    Hello YDE98
    Not sure but using UsedRange is not completly usefull, perhaps needs to check count of rows and columns, and check if TypeName(usedRange.Value) is array of string, variant, ... if UsedRange.Value is Empty or not, ....

  4. #4
    Registered User
    Join Date
    02-05-2025
    Location
    BELGIUM
    MS-Off Ver
    EXCEL
    Posts
    7

    Re: Macro Search tool for File Explorer in Folders/ Subsolders - more userfriendly

    Hi,

    not sure how to check or look into this. like i noted im not that experienced.

    If someone could help to add the changes, much appreciated !!

  5. #5
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,964

    Re: Macro Search tool for File Explorer in Folders/ Subsolders - more userfriendly

    Try this...All depends on the setup of your files...
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Sintek; 02-05-2025 at 07:52 AM.

  6. #6
    Registered User
    Join Date
    02-05-2025
    Location
    BELGIUM
    MS-Off Ver
    EXCEL
    Posts
    7

    Re: Macro Search tool for File Explorer in Folders/ Subsolders - more userfriendly

    Hi Sintek,

    The userform is indeed what i was looking for.

    I've tested the code but it seems to bug somewhere.
    I've entered a word to search, but once i confirm the folder where to look in.
    Nothing happens, no results are shown in the Result sheet.

    *as a test i made a folder with several subfolders, containing a copy in each subf

    But no results.

    Maybe it does need a tweak somewhere?

  7. #7
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,964

    Re: Macro Search tool for File Explorer in Folders/ Subsolders - more userfriendly

    Maybe it does need a tweak somewhere?
    Possibly Yes...As it works for me...
    As I said in Post 2 and 5 above...
    Can you give us an idea of how the setup of these files look...Perhaps upload a sample of 1...
    depends on the setup of your files...
    So please do so now...perhaps 2 0r 3 samples of exact setup of files...

  8. #8
    Registered User
    Join Date
    02-05-2025
    Location
    BELGIUM
    MS-Off Ver
    EXCEL
    Posts
    7

    Re: Macro Search tool for File Explorer in Folders/ Subsolders - more userfriendly

    ive added a file above in my post above, see *Example file: * with just random words in different cells.

    like this:
    apple pear banana kiwi
    apple1 pear1 banana1 kiwi1
    apple2 pear2 banana2 kiwi2
    ... ..... ... ....

    As a test with your macro, i was searching for "KIWI" & selected the folder.
    normally there should be 28 results, as column D contains the word 28times in my file.
    *keeping in mind that there are a couple subfolders containing a copy of the same file
    So 3 copies in total, should be resulting in 3 times 28 = 84 results.*

    Maybe my code could be adapted with the userform? and the option to look in subfolders?
    As my code works but i dont realy know how to implement the 'userform into the code and look in subfolder function'

    again i really appreciate ur help on this

  9. #9
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,964

    Re: Macro Search tool for File Explorer in Folders/ Subsolders - more userfriendly

    normally there should be 28 results, as column D contains the word 28times in my file.
    You did not mention anything about wildcard searches or multiple searches per sheet...

    So...Please be transparent in the following...Is it always in the active sheet...is it always in Col D or anywhere in sheet...is there multiple entries in multiple sheets etc etc

    Maybe my code could be adapted with the userform
    Your code will prove to be slow in it's processing...opening all the files and then searching the cells in sheet takes time...
    My option does all in memory without needing to open the files...


    This below...Will search all data in all rows and columns for a wildcard...See attached...
    Attached Files Attached Files
    Last edited by Sintek; 02-05-2025 at 10:38 AM.

  10. #10
    Registered User
    Join Date
    02-05-2025
    Location
    BELGIUM
    MS-Off Ver
    EXCEL
    Posts
    7

    Re: Macro Search tool for File Explorer in Folders/ Subsolders - more userfriendly

    my appologies, im not familiar with forums and presenting my question as im new here.

    Therefor i copied my code so it would be clear what it does and what i wanted to be tweaked in the original code.

    So, i'll recap..

    The macro i have, searches for a string in multiple workbooks and within each workbook in each sheet of the XLSX. But in 1 Folder.
    the string can be found in all the cells, like using CTRL+F, where this functions gives u each result, containing the string. for example in my file the string is *KIWI*.
    result to be found= KIWI; KIWI1; KIWI2; KIWI3; .... ; KIWI27
    -> This gives 28 results, the result must/are likey be given in the columns WORD SEARCHED PATH OF FOLDER FOLDER NAME FILE NAME SHEET NAME CELL ADDRESS in a new sheet generated after the search is finished.

    So the search must find all the words that contains anything with "KIWI" (wildcard search indeed)
    Like my Macro already did.

    What i would like to have the userform implemented, is the texbox and a button, where u can add the searchstring and run it by the button.

    and the functionality to have the macro to look into the subfolders (of the selected folder) where there might be more XLSX, containing multiple sheets, where the cells might contain anything with "KIWI".
    selected folder = Downloads\macro
    end subfolder = Downloads\macro\copy\copy copy

    then all the results must be shown as mentioned in this post:
    WORD SEARCHED PATH OF FOLDER FOLDER NAME FILE NAME SHEET NAME CELL ADDRESS


    As given im not an expert with VBA and Coding. nor i have experience with this.
    I just happen to found my macro online, which is allready very helpfull but not that userfriendly.
    therefor i want a userform the give in the searchstring.
    And the option to look into the subfolders, as this is not forseen in my macro, therefor i have to select each folder seperatly and run it one by one. until i reached the last subfolder.

  11. #11
    Registered User
    Join Date
    02-05-2025
    Location
    BELGIUM
    MS-Off Ver
    EXCEL
    Posts
    7

    Re: Macro Search tool for File Explorer in Folders/ Subsolders - more userfriendly

    will look into the newly posted macro by u

  12. #12
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,964

    Re: Macro Search tool for File Explorer in Folders/ Subsolders - more userfriendly

    Thank you for clarifying...
    within each workbook in each sheet
    So...Is there possibly multiple sheets per file...

  13. #13
    Registered User
    Join Date
    02-05-2025
    Location
    BELGIUM
    MS-Off Ver
    EXCEL
    Posts
    7

    Re: Macro Search tool for File Explorer in Folders/ Subsolders - more userfriendly

    yes

    So for all the workbooks in the selected folder, and subfolders, each workbook can contain multiple sheets > Not knowing this in advance.

    so it might be possible there are workbooks with 1 sheet, but other workbooks with multiple sheets ( an X number of sheet).
    Like the CTRL+F 'find and replace' in excel can search over the whole workbook. this function, but than over multiple workbooks in a folder and its subfolders.

  14. #14
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,964

    Re: Macro Search tool for File Explorer in Folders/ Subsolders - more userfriendly

    Understood...File in post 9 is for just one sheet...This will loop all sheets in workbooks...
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Sintek; 02-05-2025 at 11:30 AM.

+ 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. Tweaking my excel sheet to search in explorer for a certain .pdf file as show in the cell
    By MaartenValmont in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-11-2022, 04:28 PM
  2. Replies: 1
    Last Post: 07-08-2022, 09:08 AM
  3. Replies: 8
    Last Post: 09-11-2017, 01:35 PM
  4. [SOLVED] Search for file names in main folder and its sub folders
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 11-09-2015, 01:17 AM
  5. Search for file in a directory and all sub folders inside
    By som3on3_10 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-11-2015, 12:57 AM
  6. Macro - Open File Explorer, Select File, Import certain information from file
    By Drayde in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-25-2015, 08:58 AM
  7. Command button(SEARCH) to open windows explorer to select file
    By sameerk0286 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-23-2010, 09:38 AM

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