PDA

View Full Version : Solved: Find String



vzachin
09-20-2008, 10:34 AM
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

jproffer
09-20-2008, 10:43 AM
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?

vzachin
09-20-2008, 11:03 AM
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

vzachin
09-20-2008, 11:27 AM
i forgot to check the Help files...d-u-h

With Range("e24")
Set c = .Find(Range("e2"))
If Not c Is Nothing Then
MsgBox "found"
End If
End With



embarassed

Bob Phillips
09-20-2008, 11:56 AM
If it is just one cell, why not just



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

Msgbox "Found"
End If

jproffer
09-20-2008, 06:31 PM
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.

Bob Phillips
09-21-2008, 12:41 AM
Ifr it is contained, you would use



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

Msgbox "Found"
End If

jproffer
09-21-2008, 06:21 AM
Learned something new. Thank you sir :)