+ Reply to Thread
Results 1 to 6 of 6

To find in all the worksheets of all the workbooks in a directory/ Drive and copy

Hybrid View

  1. #1
    Registered User
    Join Date
    01-06-2012
    Location
    Lahore, Pakistan
    MS-Off Ver
    Excel 2007
    Posts
    51

    To find in all the worksheets of all the workbooks in a directory/ Drive and copy

    I have a problem that my data is saved on various Excel workbooks in D-Drive of my hard disk. I want to have macro that will help me to find a specific word (lets say " Dhoom" ) anywhere in any workbook (and on any sheet of that work book) and than copy the entire row of that work sheet and paste it on a particular work book (work sheet). I would be thankful if someone can help me in this regard.

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: To find in all the worksheets of all the workbooks in a directory/ Drive and copy

    Sub macro_find_all_wbs(dir_path As String, search_text As String)
    Dim fso, fol, fil, wb1, wb2, sh1, sh2, fnd_rng, count_row
    Set wb1 = ActiveWorkbook
    Set sh1 = wb1.ActiveSheet
    Set fso = CreateObject("Scripting.filesystemobject")
    Set fol = fso.getfolder(dir_path)
    For Each fil In fol.Files
        Set wb2 = Workbooks.Open(fil)
        For Each sh2 In wb2.Sheets
            Set fnd_rng = sh2.Cells.Find(search_text)
            Do Until fnd_rng Is Nothing Or rnd_rng.Row < count_row
                fnd_rng.EntireRow.Copy sh1.Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
                count_row = fnd_rng.Row
                Set fnd_rng = sh2.Cells.FindNext(rnd_rng)
            Loop
        Next
    Next
    End Sub
    Something like that perhaps?

  3. #3
    Registered User
    Join Date
    01-06-2012
    Location
    Lahore, Pakistan
    MS-Off Ver
    Excel 2007
    Posts
    51

    Re: To find in all the worksheets of all the workbooks in a directory/ Drive and copy

    Dear Yudlagar
    It doesnt work. As i dont know where to give my input word, which i wanna find through all workbooks.

  4. #4
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: To find in all the worksheets of all the workbooks in a directory/ Drive and copy

    Sorry, use it like this:
    sub macro_1()
      call macro_find_all_wbs("C:\path","Searchtext")
    end sub
    
    Sub macro_find_all_wbs(dir_path As String, search_text As String)
    Dim fso, fol, fil, wb1, wb2, sh1, sh2, fnd_rng, count_row
    Set wb1 = ActiveWorkbook
    Set sh1 = wb1.ActiveSheet
    Set fso = CreateObject("Scripting.filesystemobject")
    Set fol = fso.getfolder(dir_path)
    For Each fil In fol.Files
        Set wb2 = Workbooks.Open(fil)
        For Each sh2 In wb2.Sheets
            Set fnd_rng = sh2.Cells.Find(search_text)
            Do Until fnd_rng Is Nothing Or rnd_rng.Row < count_row
                fnd_rng.EntireRow.Copy sh1.Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
                count_row = fnd_rng.Row
                Set fnd_rng = sh2.Cells.FindNext(rnd_rng)
            Loop
        Next
    Next
    End Sub

  5. #5
    Registered User
    Join Date
    01-06-2012
    Location
    Lahore, Pakistan
    MS-Off Ver
    Excel 2007
    Posts
    51

    Re: To find in all the worksheets of all the workbooks in a directory/ Drive and copy

    Dear Yudlagar

    This time the code works a little better, i mean it is bringing some data...but it does not bring the required cells (containing the desired words) nor it brings all of its row etc.
    i just need to find any specific word say " Dhoom" or " Max" etc. anywhere in a workbook and copy the entire row of that cell to my desired place.
    Thnx

  6. #6
    Registered User
    Join Date
    01-06-2012
    Location
    Lahore, Pakistan
    MS-Off Ver
    Excel 2007
    Posts
    51

    Re: To find in all the worksheets of all the workbooks in a directory/ Drive and copy

    dear cant anyone help me in this regard anymore?

+ 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. Macro that goes through several workbooks and worksheets in the same directory
    By awcwa in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-07-2013, 11:08 PM
  2. find file in directory, copy and paste worksheet
    By inky in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-04-2008, 08:52 AM
  3. Copy sheet to all workbooks in a directory AND..
    By mikeyfear in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-12-2008, 03:00 AM
  4. [SOLVED] Changing to different drive and directory
    By Rob in forum Excel General
    Replies: 5
    Last Post: 07-19-2006, 11:15 PM
  5. [SOLVED] Link workbooks-C drive to network drive
    By Earl in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 04-19-2005, 01:07 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