+ Reply to Thread
Results 1 to 5 of 5

Search text in worksheet

Hybrid View

  1. #1
    Registered User
    Join Date
    05-10-2015
    Location
    Bucharest,Romania
    MS-Off Ver
    2010
    Posts
    14

    Cool Search text in worksheet

    Dear colleagues,

    Recently I've been trying to adapt a search code that I've found to try to find a word in a worksheet.

    The code is meant to find, and select all cells that contains the text from an inputbox.
    Code :

    Private Sub CommandButton3_Click()
        Dim ThisAddress$, Found, FirstAddress
        Dim Lost$, N&, NextSheet&
        Dim CurrentArea As Range, SelectedRegion As Range
        Dim Reply As VbMsgBoxResult
        Dim FirstSheet As Worksheet
        Dim Ws As Worksheet
        Dim Wks As Worksheet
        Dim Sht As Worksheet
        Set FirstSheet = ActiveSheet
        Lost = InputBox(prompt:="Cuvinte cheie", _
        Title:="Cuvinte cheie:")
        If Len(Trim(Lost)) = 0 Then End
        For Each Ws In Worksheets
            Ws.Select
            With ActiveSheet.Cells
                Set FirstAddress = .Find(What:=Lost, LookIn:=xlValues)
                If FirstAddress Is Nothing Then '< blank sheet
                GoTo NextSheet
                End If
                FirstAddress.Select
                With Selection
                                Set Found = .Find(What:=Lost, LookIn:=xlValues)
                    If Not Found Is Nothing Then
                        FirstAddress = Found.Address
                        Do
                        Set Found = .FindNext(Found)
                        Loop While Not Found Is Nothing And Found. _
                        Address <> FirstAddress
                    End If
                End With
                Reply = MsgBox("Acesta este " & Lost & " pe care il cautai?", _
                vbQuestion + vbYesNoCancel, "Selectie activa")
                Set Found = .Find(What:=Lost, LookIn:=xlValues)
                If Not Found Is Nothing Then
                    FirstAddress = Found.Address
                    Do
                    Set Found = .FindNext(Found)
                    Loop While Not Found Is Nothing And Found. _
                    Address <> FirstAddress
                End If
                Set FirstAddress = .Find(What:=Lost, LookIn:=xlValues)
                If Reply = vbCancel Then End
                If Reply = vbYes Then
                Set SelectedRegion = Selection
    GoTo Finish:
                End If
                ThisAddress = FirstAddress.Address
                Set CurrentArea = Selection
                Do
                    If Intersect(CurrentArea, Selection) Is Nothing Then
                        With Selection.Interior
                        End With
                        With Selection
                            Set Found = .Find(What:=Lost, LookIn:=xlValues)
                            If Not Found Is Nothing Then
                                FirstAddress = Found.Address
                                Do
                                    Set Found = .FindNext(Found)
                                Loop While Not Found Is Nothing And Found. _
                                Address <> FirstAddress
                            End If
                        End With
                        Reply = MsgBox("Acesta este " & Lost & " pe care il cautai?", _
                        vbQuestion + vbYesNoCancel, "Current Region")
                        Set Found = .Find(What:=Lost, LookIn:=xlValues)
                        If Not Found Is Nothing Then
                            FirstAddress = Found.Address
                            Do
                                Set Found = .FindNext(Found)
                            Loop While Not Found Is Nothing And Found. _
                            Address <> FirstAddress
                        End If
                        Set FirstAddress = .Find(What:=Lost, _
                        LookIn:=xlValues)
                        If Reply = vbCancel Then End
                        If Reply = vbYes Then
                            Set SelectedRegion = Selection
    GoTo Finish:
                        End If
                    End If
                    If CurrentArea Is Nothing Then
                        Set CurrentArea = Selection
                    Else
                        Set CurrentArea = Union(CurrentArea, Selection)
                    End If
                    Set FirstAddress = .FindNext(FirstAddress)
                    FirstAddress.Select
                Loop While Not FirstAddress Is Nothing And FirstAddress. _
                Address <> ThisAddress
        End With
    NextSheet:
        Next Ws
    Finish:
        If Reply = vbYes Then
            Exit Sub
        Else
            FirstSheet.Select
            MsgBox "Search Completed - Sorry, no more " & Lost & "s", _
            vbInformation, "No Region Selected"
        End If
    End Sub
    The only problem that I have is that I want to add a condition in it, and I don't know how.... I want the code to skip selecting valid cells (cells that have the inputbox word in them), that have the text size <10 . Recapping, now the code selects and displays all cells that have the inputbox word in them, but I want it to select just the ones that have the text size > 10. Any ideas would be appreciated.


    Warm regards,


    Eugeniu

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Search text in worksheet

    What do you want too do once the cell has been selected? Create a list? Highlight?

  3. #3
    Registered User
    Join Date
    05-10-2015
    Location
    Bucharest,Romania
    MS-Off Ver
    2010
    Posts
    14

    Re: Search text in worksheet

    Dear John,

    The Workbook in which I will use this code is protected, so my options aren't that many:P. I just want to select the specific cell.

    Warm regards,

    Eugeniu

  4. #4
    Registered User
    Join Date
    05-10-2015
    Location
    Bucharest,Romania
    MS-Off Ver
    2010
    Posts
    14

    Re: Search text in worksheet

    Any new idea will be appreciated .

  5. #5
    Registered User
    Join Date
    05-10-2015
    Location
    Bucharest,Romania
    MS-Off Ver
    2010
    Posts
    14

    Re: Search text in worksheet

    Also, I've tried changing up the
    LookIn:=xlValues
    in order to make it search just the cells that have text.size > 10. No luck.


    Regards,

    Eugeniu

+ 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. Replies: 1
    Last Post: 04-06-2015, 05:10 PM
  2. Search Worksheet for Text
    By windowshopr in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 07-24-2013, 02:15 AM
  3. [SOLVED] Search function to search if worksheet contains specified text
    By mougiasm in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-07-2013, 02:50 PM
  4. Search text from another worksheet
    By rajeev.raj in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-15-2010, 07:55 AM
  5. Excel 2007 – Search for highlighted text and copy to another worksheet.
    By DHopgood@sms in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-07-2010, 01:58 AM
  6. Replies: 1
    Last Post: 02-22-2010, 05:25 PM
  7. text search insert a row on a second worksheet
    By Chuck101 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 03-14-2008, 06:09 AM

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