Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default Macro: Finding Text Within Text

I need to determine whether a cell contains a particular string of text, what
is the best function or way of doing this in my macro?

For Example:
I want to know whether cell A1 contains the text "AUA", if it does then I'm
going to execute some code, if it doesn't then I'm going to execute some
other code. I was trying to use the Range.Find method but I had a lot of
trouble with it.

Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Macro: Finding Text Within Text

maybe something simple like this:

Sub test()
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")

With ws
If InStr(.Range("A1"), "AUA") Then
MsgBox "found"
End If
End With

End Sub

--


Gary

"Simon" wrote in message
...
I need to determine whether a cell contains a particular string of text,
what
is the best function or way of doing this in my macro?

For Example:
I want to know whether cell A1 contains the text "AUA", if it does then
I'm
going to execute some code, if it doesn't then I'm going to execute some
other code. I was trying to use the Range.Find method but I had a lot of
trouble with it.

Thanks.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default Macro: Finding Text Within Text

Hi

You don't say if you want a case sensitive function, so I have made it case
sensitive by setting MatchCase=True.

Here's a way to do it:

Set f = Range("A1").Find(what:="AUA", MatchCase:=True)
If f Is Nothing Then
MsgBox "Not found"
Else
MsgBox "Found"
End If

Regards,
Per
"Simon" skrev i meddelelsen
...
I need to determine whether a cell contains a particular string of text,
what
is the best function or way of doing this in my macro?

For Example:
I want to know whether cell A1 contains the text "AUA", if it does then
I'm
going to execute some code, if it doesn't then I'm going to execute some
other code. I was trying to use the Range.Find method but I had a lot of
trouble with it.

Thanks.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding text or part of a text inside the value cell [email protected] Excel Programming 1 November 23rd 07 06:19 PM
Finding text in a cell and returning a value based on that text [email protected] Excel Discussion (Misc queries) 5 January 10th 07 06:01 PM
Finding Specific Text in a Text String Peter Gundrum Excel Worksheet Functions 9 April 10th 05 07:21 PM
Find WorksheetFunction - finding text within text Marcotte A Excel Programming 1 January 24th 05 10:16 PM
Macro query - finding mutliple occurences of text in a column Mcneilius[_3_] Excel Programming 2 September 1st 04 08:00 PM


All times are GMT +1. The time now is 10:39 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"