Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2013
    Posts
    7

    Unanswered: search string1, if not found search string2

    Greetings,

    I need some help in figuring out this macro. Below is a snippet of a text file I am opening with the excel macro:

    I search for the text shown below in red, "FbrSyn" and make that the activeCell and do what I need to do. However that text can be either "DbrSyn or "E1brSyn" or "FbrSyn". I am not having any luck correctly making the text search using an OR statement.

    Portion of Text file- - - - - - - -
    66
    1
    100
    AcDbBlockReference
    2
    FbrSyn
    10
    0.0
    20
    0.0
    30
    0.0
    Portion of Text file- - - - - - - -

    Portion of Text file- - - - - - - -

    This portion of the code works fine for getting to the cell containing "DbrSyn". How do I change it so that after Selection.Find(What:="DbrSyn" or "E1brSyn" or "FbrSyn"?

    Columns("A:A").Select
    Range(Cells(1, 1), Cells(Rows.Count, 1).End(xlUp)).Select
    Selection.Find(What:="DbrSyn", After:=ActiveCell, LookIn:=xlFormulas, _
    LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False).Activate
    ActiveCell.Select

    Thanks for any help,
    Doug
    Last edited by DougRW; 11-18-13 at 22:10.

  2. #2
    Join Date
    Jan 2002
    Location
    Bay Area
    Posts
    511
    Someone may come up with a solution that includes the 3 possible targets.
    If your data is guaranteed not to use "Syn" except on the row you are
    searching for, the code below works for me, by just searching for "Syn".
    Code:
    Sub Try_This()
    Dim rngFound As Range
        
        strTarget = "Syn"
        
        Columns("A:A").Select
        Range(Cells(1, 1), Cells(Rows.Count, 1).End(xlUp)).Select
        
        On Error Resume Next
        Set rngFound = Cells.Find(What:=strTarget, After:=ActiveCell, LookIn:=xlFormulas, _
            LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=True, SearchFormat:=False)
        On Error GoTo 0
            
        If rngFound Is Nothing Then
            MsgBox "Target not found: " & strTarget
            Exit Sub
        Else
            rngFound.Select
        End If
        
    End Sub

  3. #3
    Join Date
    Oct 2013
    Posts
    7
    JerryDal,

    Thanks for the reply. I had sort of given up on getting an answer. I will try this out on Monday when I get back to work.

    Thanks again,
    Doug

Posting Permissions

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