Results 1 to 6 of 6
  1. #1
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Search or Some Other Worksheet Function (03)

    I am processing a flat file and looking at each line within the file to determine if some text exists in the line such as "Total Processed".

    Would it be better to use the "Search" or some other worksheet function to test for the text ("Total Processed").

    What I would like to accomplish is something like:
    Search for "Total Processed"
    If not found or error occurs; bring in another line and continue the search
    If found, run some code

    Thanks,
    John

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Search or Some Other Worksheet Function (03)

    What do you mean by a "flat" file? A text file, or ...?

  3. #3
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Search or Some Other Worksheet Function (03)

    Hans,

    That would be a text file.

    Regards,
    John

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Search or Some Other Worksheet Function (03)

    What method are you using to open the text file and to read lines from it?

  5. #5
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Search or Some Other Worksheet Function (03)

    Hans,

    This is the code but it is still a work in progress:

    Dim LineofText As String
    Set af = Application.WorksheetFunction
    Open FileToOpen For Input As #1
    Do While Not EOF(1)
    Line Input #1, LineofText
    Range("TextLine") = LineofText
    On Error GoTo SkipCode
    MsgBox af.Search("Total Processed", Range("TextLine"))
    SkipCode:
    Loop
    Close #1
    Exit Sub

    PostEntry:
    MsgBox af.Search("Total Processed", Range("TextLine"))
    Return

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Search or Some Other Worksheet Function (03)

    After the instruction

    Line Input #1, LineofText

    you can inspect the variable LineOfText. If you want to know whether the text "Total Processed" occurs in the string, you can use

    If InStr(LineOfText, "Total Processed") > 0 Then
    ...
    End If

    This is case sensitive; if you want to compare case insensitive, you can use

    If InStr(1, LineOfText. "Total Processed", vbCompareText) > 0 Then

    or

    If InStr(LCase(LineOfText), "total processed") > 0 Then

Posting Permissions

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