+ Reply to Thread
Results 1 to 2 of 2

Help! Searching for text with more than one criteria

  1. #1
    Registered User
    Join Date
    07-11-2005
    Posts
    38

    Help! Searching for text with more than one criteria

    Hi,

    I have a text file that is formatted in a way like this:

    Department #
    Responsible person:
    labor distribution

    Here is my code so far:

    Sheets("Sheet3").Select
    Range("A1").Select
    Open "C:\Documents and Settings\Kevin\desktop\ebc440.txt" For Input As #1
    texttofind = "DEPARTMENT 33290"
    Do Until EOF(1)
    Line Input #1, data
    If InStr(1, data, texttofind) Then
    ActiveCell.Offset(r, 0) = data
    r = r + 1
    End If
    Loop
    Close

    How do I code it so that I can add more criteria like "labor" and "responsible person" and not just the department 33290". Please help, thanks in advance!

  2. #2
    Registered User
    Join Date
    07-13-2005
    Posts
    15
    you can use the AND function in the IF statement at the top to define multiple instances of the INSTR(...) test (or the OR function etc..)


    i.e.

    If InStr(1, data, texttofind) AND InStr(1, data, texttofind2) Then
    ...
    ...
    ENDIF

    where texttofind2 is your second search criteria.

    if you want to seach for a string but don't know what you will be looking for when writing the code then a simple INPUT box statement can receive you text without the need for a dialogbox with all the associated code:

    texttofind = INPUTBOX ("Enter Search Text")

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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