Results 1 to 6 of 6

Thread: Search word in different workbooks and sheets

Hybrid View

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

    Search word in different workbooks and sheets

    Hello to all.
    I would like to ask you if you find someone who can help me with these two macros that work very well but for certain things. So because I do not understand many will not explain what the problem is:
    The first is made so that the popup window to search for a word in countless workbooks, it does but only in the open sheet of the workbook. So you can be less that the revised starting from the first workbook, going through all the paper then goes to the second sheet and check all the way to the end?
    Code:
    Sub SearchBookss()
    SearchWord = InputBox("Enter the string to search for")
    For i = 1 To Workbooks.Count
    Workbooks(i).Activate
    Range("A1").Activate
    FindAnother:
    Set WordAddress = Cells.Find(What:=SearchWord, after:=ActiveCell, LookIn:=xlFormulas, lookat:= _
    xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
    If WordAddress Is Nothing Then
    MsgBox ActiveWorkbook.Name & Chr(13) & "Search string not found"
    Else:
    If WordAddress.Address = CheckCell Then GoTo NextBook
    If ActiveCell.Address = "$A$1" Then CheckCell = WordAddress.Address
    Address = WordAddress.Address
    MsgBox ActiveWorkbook.Name & Chr(13) & Address
    Range(Address).Activate
    GoTo FindAnother
    End If
    NextBook:
    Next i
    End Sub
    I want to thank you in advance for all your help.
    Last edited by Admin; 11-29-2012 at 02:15 PM.

  2. #2
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi k0st4din,

    Welcome to ExcelFox!!

    Ask the questions one by one.

    try this one.

    Code:
    Sub SearchBookss()
        
        Dim Sht     As Worksheet
        
        SearchWord = InputBox("Enter the string to search for")
        For i = 1 To Workbooks.Count
            For Each Sht In Workbooks(i).Worksheets
    FindAnother:
                Set WordAddress = Sht.UsedRange.Find(What:=SearchWord, after:=Sht.Cells(1), LookIn:=xlFormulas, lookat:= _
                                xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
                If Not WordAddress Is Nothing Then
                    If WordAddress.Address = CheckCell Then GoTo NextBook
                    If WordAddress.Address = "$A$1" Then CheckCell = WordAddress.Address
                    Address = WordAddress.Address
                    MsgBox Workbooks(i).Name & Chr(13) & Address
                    Sht.Range(Address).Activate
                    GoTo FindAnother
                End If
            Next
    NextBook:
        Next i
    End Sub

    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    https://www.youtube.com/watch?v=zHJPliWS9FQ&lc=Ugz39PGfytiMUCmTPTl4AaABAg. 91d_Pbzklsp9zfGbIr8hgW
    https://www.youtube.com/watch?v=zHJPliWS9FQ&lc=UgwbcybM8fXnaIK-Y3B4AaABAg.97WIeYeaIeh9zfsJvc21iq
    https://www.youtube.com/watch?v=vSjTzhoJFdk&lc=UgzTC8V4jCzDHbmfCHF4AaABAg. 9zaUSUoUUYs9zciSZa959d
    https://www.youtube.com/watch?v=vSjTzhoJFdk&lc=UgzTC8V4jCzDHbmfCHF4AaABAg. 9zaUSUoUUYs9zckCo1tvPO
    https://www.youtube.com/watch?v=vSjTzhoJFdk&lc=UgwMsgdKKlhr2YPpxXl4AaABAg
    https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgwTUdEgR4bdt6crKXF4AaABAg. 9xmkXGSciKJ9xonTti2sIx
    https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgwWw16qBFX39JCRRm54AaABAg. 9xnskBhPnmb9xoq3mGxu_b
    https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgzgWvzV-kvC4TJ8O414AaABAg.9xnFzCj8HRM9xon1p2ImxO
    https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgybZfNJd3l4FokX3cV4AaABAg. 9xm_ufqOILb9xooIlv5PLY
    https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgzgWvzV-kvC4TJ8O414AaABAg.9xnFzCj8HRM9y38bzbSqaG
    https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgyWm8nL7syjhiHtpBF4AaABAg. 9xmt8i0IsEr9y3FT9Y9FeM
    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    Last edited by DocAElstein; 03-02-2024 at 02:48 PM.
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  3. #3
    Member
    Join Date
    Nov 2012
    Posts
    47
    Rep Power
    0
    Hello Mr. Admin,
    I did not do it intentionally, you're really just going for two different issues. I promised it would not happen again.
    Thank you from my heart.
    Another thing gives me error (Ln16, Col 1) - (Sht.Range (Address). Activate)
    Run-time error '1004':
    Method 'Range' of object'_Worksheet' failed

    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    https://www.eileenslounge.com/viewtopic.php?p=312533#p312533
    https://www.eileenslounge.com/viewtopic.php?f=44&t=40373&p=312499#p312499
    https://www.youtube.com/watch?v=jTmVtPHtiTg&lc=Ugy_RiNN_kAqUvZ8W994AaABAg. 9xhyRrsUUOM9xpn-GDkL3o
    https://www.youtube.com/watch?v=jTmVtPHtiTg&lc=Ugy_RiNN_kAqUvZ8W994AaABAg
    https://www.youtube.com/watch?v=jTmVtPHtiTg&lc=UgzlC5LBazG6SMDP4nl4AaABAg
    https://www.youtube.com/watch?v=jTmVtPHtiTg&lc=UgzlC5LBazG6SMDP4nl4AaABAg. 9zYoeePv8sZ9zYqog9KZ5B
    https://www.youtube.com/watch?v=jTmVtPHtiTg&lc=Ugy_RiNN_kAqUvZ8W994AaABAg. 9xhyRrsUUOM9zYlZPKdOpm
    https://www.youtube.com/watch?v=QjEWAJ3d-jw&lc=UgxJLVpwY8fIla7G-pN4AaABAg.9BLeCWVhxdG9wgNsaS3Lp1
    https://www.youtube.com/watch?v=QjEWAJ3d-jw&lc=UgxJLVpwY8fIla7G-pN4AaABAg.9BLeCWVhxdG9wgR1EPUkhw
    https://www.youtube.com/watch?v=QjEWAJ3d-jw&lc=UgxJLVpwY8fIla7G-pN4AaABAg.9BLeCWVhxdG9wgNe_XC-jK
    https://www.youtube.com/watch?v=QjEWAJ3d-jw&lc=UgxJLVpwY8fIla7G-pN4AaABAg.9BLeCWVhxdG9wgNPOdiDuv
    https://www.youtube.com/watch?v=QjEWAJ3d-jw&lc=UgxJLVpwY8fIla7G-pN4AaABAg.9BLeCWVhxdG9wgN7AC7wAc
    https://www.youtube.com/watch?v=bs-urI_o8jo&lc=UgyBACXgNY4j_cHgH5J4AaABAg.9oTkVdzfqfm 9wlhQrYJP3M
    https://www.youtube.com/watch?v=bs-urI_o8jo&lc=UgxYgiEZuS9I3xkjJv54AaABAg
    https://www.youtube.com/watch?v=DVFFApHzYVk&lc=Ugyi578yhj9zShmhuPl4AaABAg
    https://www.youtube.com/watch?v=GqzeFYWjTxI&lc=UgxvxlnuTRWiV6MUZB14AaABAg
    https://www.youtube.com/watch?v=_8i1fVEi5WY&lc=Ugz0ptwE5J-2CpX4Lzh4AaABAg
    https://www.youtube.com/watch?v=0ltJS7uHfK4&lc=UgxoHAw8RwR7VmyVBUt4AaABAg. 9C-br0lEl8V9xI0_6pCaR9
    https://www.youtube.com/watch?v=0ltJS7uHfK4&lc=Ugz5DDCMqmHLeEjUU8t4AaABAg. 9bl7m03Onql9xI-ar3Z0ME
    https://www.youtube.com/watch?v=0ltJS7uHfK4&lc=UgxYnpd9leriPmc8rPd4AaABAg. 9gdrYDocLIm9xI-2ZpVF-q
    https://www.youtube.com/watch?v=0ltJS7uHfK4&lc=UgyjoPLjNeIAOMVH_u94AaABAg. 9id_Q3FO8Lp9xHyeYSuv1I
    https://www.reddit.com/r/windowsxp/comments/pexq9q/comment/k81ybvj/?utm_source=reddit&utm_medium=web2x&context=3
    https://www.youtube.com/watch?v=bs-urI_o8jo&lc=UgxYgiEZuS9I3xkjJv54AaABAg
    https://www.youtube.com/watch?v=bs-urI_o8jo&lc=UgyBACXgNY4j_cHgH5J4AaABAg.9oTkVdzfqfm 9wlhQrYJP3M
    ttps://www.youtube.com/watch?v=LP9fz2DCMBE
    https://www.youtube.com/watch?v=LP9fz2DCMBE&lc=UgzbPgJUMCztIOQDym14AaABAg
    https://www.youtube.com/watch?v=LP9fz2DCMBE&lc=UgzbPgJUMCztIOQDym14AaABAg. 9wdo_rWgxSH9wdpcYqrvp8
    ttps://www.youtube.com/watch?v=bFxnXH4-L1A
    https://www.youtube.com/watch?v=bFxnXH4-L1A&lc=UgxuODisjo6cvom7O-B4AaABAg.9w_AeS3JiK09wdi2XviwLG
    https://www.youtube.com/watch?v=bFxnXH4-L1A&lc=UgxBU39bTptFznDC1PJ4AaABAg
    ttps://www.youtube.com/watch?v=GqzeFYWjTxI
    https://www.youtube.com/watch?v=GqzeFYWjTxI&lc=UgwJnJDJ5JT8hFvibt14AaABAg
    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    Last edited by DocAElstein; 03-02-2024 at 02:47 PM.

  4. #4
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi

    Dim the variables properly. This should work.

    Code:
    Sub SearchBookss()
        
        Dim Sht             As Worksheet
        Dim SearchWord      As String
        Dim WordAddress     As Range
        Dim CheckCell       As String
        Dim Addr            As String
        Dim i   As Long
        
        Application.ScreenUpdating = 0
        
        SearchWord = InputBox("Enter the string to search for")
        On Error GoTo Xit
        For i = 1 To Workbooks.Count
            For Each Sht In Workbooks(i).Worksheets
                Application.Goto Sht.Cells(1)
    FindAnother:
                Set WordAddress = Sht.UsedRange.Find(What:=SearchWord, lookat:=xlPart, MatchCase:=False)
                If Not WordAddress Is Nothing Then
                    CheckCell = WordAddress.Address
                    Do
                        Set WordAddress = Sht.UsedRange.FindNext(WordAddress)
                        Addr = WordAddress.Address
                        MsgBox Workbooks(i).Name & Chr(13) & Sht.Name & vbLf & Addr
                    Loop Until Addr = CheckCell
                    Application.Goto Sht.Range(CheckCell)
                End If
            Next
    NextBook:
        Next i
        Application.ScreenUpdating = 1
        Exit Sub
    Xit:
        MsgBox Err.Description
        Application.ScreenUpdating = 1
    End Sub
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  5. #5
    Member
    Join Date
    Nov 2012
    Posts
    47
    Rep Power
    0
    Yes it works seamlessly. No errors.
    Thank you very much Mr. Admin

  6. #6

Similar Threads

  1. Replies: 7
    Last Post: 08-24-2015, 10:58 PM
  2. Replies: 3
    Last Post: 05-14-2013, 03:25 PM
  3. Replies: 2
    Last Post: 11-08-2012, 01:15 PM
  4. Replies: 1
    Last Post: 10-16-2012, 01:53 PM
  5. VBA Function to Search in Array
    By Admin in forum Excel and VBA Tips and Tricks
    Replies: 0
    Last Post: 04-10-2012, 11:34 AM

Posting Permissions

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