Consulting

Results 1 to 8 of 8

Thread: Solved: Find String

  1. #1
    VBAX Tutor
    Joined
    Feb 2006
    Posts
    295
    Location

    Solved: Find String

    hi,

    i want to see if a string that is defined in range("e2") exists in
    range("e24"). if it does, then i want a msgbox that will say "exists".

    the string in range("e2") will vary.

    i recorded a macro but i don't know how to point it to range("e2") and then look at range("e24") only.

    any ideas?


    thanks
    zach

  2. #2
    VBAX Regular
    Joined
    Dec 2004
    Posts
    92
    Location
    Is it always E2 and E24? And do you mean the cell values are equal, or there is a shorter string from E2, within a longer string in E24?

    I.E. - Find string "dog" within the value of cell E24 "your doghouse is very big".

    What if there are more than one instance of the E2 string?

    I.E. - Find string "dog" within the value of cell E24 "your doghouse is very big, and your dog very small".

    Does that matter? Do you want a count, or a simple yes or no? And do you want an exact match (just "dog" and not "doghouse"), or any part of a word?

  3. #3
    VBAX Tutor
    Joined
    Feb 2006
    Posts
    295
    Location
    hi,

    it's always E2 & D24. the cells will never be equal. The E2 string will always be shorter that E24. And it may or maynot be in E24.
    If the string appears in E24, then it will be unique and appear anywhere in E24. there will not be a 2nd occurance in E24.
    i only want to check E24.

    so if the string that i have in E2 appears anywhere in E24, then a msgbox is all i need. if not found, then no msgbox.

    thanks for your thoughts
    zach

  4. #4
    VBAX Tutor
    Joined
    Feb 2006
    Posts
    295
    Location
    i forgot to check the Help files...d-u-h
    [vba]
    With Range("e24")
    Set c = .Find(Range("e2"))
    If Not c Is Nothing Then
    MsgBox "found"
    End If
    End With

    [/vba]

    embarassed

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    If it is just one cell, why not just

    [vba]

    If Range("E24").Value = Range("E2").Value Then

    Msgbox "Found"
    End If
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    VBAX Regular
    Joined
    Dec 2004
    Posts
    92
    Location
    Your reply has made me curious XLD. If they aren't technically equal, but one value is within the other, would your code yield true or false. I've never tried it like that, so I don't know...just curious.

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Ifr it is contained, you would use

    [vba]

    If Range("E24").Value Like "*" & Range("E2").Value & "*" Then

    Msgbox "Found"
    End If
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  8. #8
    VBAX Regular
    Joined
    Dec 2004
    Posts
    92
    Location
    Learned something new. Thank you sir

Posting Permissions

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