Results 1 to 8 of 8

Thread: Loop through a folder and find word

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Member
    Join Date
    Nov 2012
    Posts
    47
    Rep Power
    0

    Loop through a folder and find word

    Hello to all.

    My second problem:
    This macro also works perfectly: I open a new workbook (book1), I put my macro button to call after his appearance, immediately began to seek how many workbooks are in a folder where it is located (book1). For example, in a folder Trii / 10 I excel file that shows them to me in column A: A (book1), then in the box izkochiliyat I wanted to write about what I want to look and how to replace it - this is the same as standard option in excel (Find and Replace) but looking in all workbooks and the problem here is that the macro is designed to look at specific cells and truly replaces words.
    So the problem is whether you less to fix it to look absolutely all cells in all worksheets.
    I believe that is a matter of minor fixes somewhere in the code, but because they do not understand, I do not know where to Complete the thing.

    Code:
    Sub general()
    Dim z  As Long, e As Long, g As Long
    Dim f As String, m As String, n As String
    Sheets("Sheet1").Select
    Cells(1, 1) = "=cell(""filename"")"
    Cells(1, 2) = "=left(A1,find(""["",A1)-1)"
    Cells(2, 1).Select
    f = Dir(Cells(1, 2) & "*.xls")
        Do While Len(f) > 0
        ActiveCell.Formula = f
        ActiveCell.Offset(1, 0).Select
        f = Dir()
        Loop
    m = InputBox("Enter search string")
    n = InputBox("Enter replacement string") 'common replacement
    z = Cells(Rows.Count, 1).End(xlUp).Row
        For e = 2 To z
            If Cells(e, 1) <> ActiveWorkbook.Name Then
            Workbooks.Open Filename:=Cells(1, 2) & Cells(e, 1)
                For a = 1 To Sheets.Count
               'n = InputBox("Enter replacement string for sheet -  " & Worksheets(a).Name) ' sheetwise replacement
                x = Worksheets(a).Cells(Rows.Count, 3).End(xlUp).Row
                    For b = 2 To x
                        If InStr(Worksheets(a).Cells(b, 3), m) > 0 Then
                        Worksheets(a).Cells(b, 11) = n
                        End If
                    Next b
                Next a
            ActiveWorkbook.Close True
            End If
        Next e
    MsgBox "collating is complete."
    End Sub
    I want to thank you in advance for all your help.
    Last edited by Admin; 11-29-2012 at 02:18 PM.

Similar Threads

  1. Replies: 7
    Last Post: 08-24-2015, 10:58 PM
  2. Replies: 1
    Last Post: 05-21-2013, 11:58 AM
  3. Loop Through And Delete Multiple File Types In A Folder
    By Excel Fox in forum Excel and VBA Tips and Tricks
    Replies: 0
    Last Post: 03-30-2013, 04:47 PM
  4. Replies: 1
    Last Post: 10-16-2012, 01:53 PM
  5. Find Parent Folder From Given Folder / File Path
    By Excel Fox in forum Excel and VBA Tips and Tricks
    Replies: 1
    Last Post: 05-28-2011, 03:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •