Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
I would like to know if a String belongs to another string. for example : Dim KeyString as String Dim Sentence as String Dim Result as Interger Result = worksheetFunction.Find(KeyString,Sentence) if (Result<"") then Msgbox "KeyString exists within Senetence" EndIf but it doesn't work. i just want to check if my KeyString belongs to Sentence, that's all. basically i store into Sentence the value of a cell. thx Maileen |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try using the instr function. It returns the location of the beginning of one
text string withing another. If the string is not found it returns zero. HTH "Maileen" wrote: Hi, I would like to know if a String belongs to another string. for example : Dim KeyString as String Dim Sentence as String Dim Result as Interger Result = worksheetFunction.Find(KeyString,Sentence) if (Result<"") then Msgbox "KeyString exists within Senetence" EndIf but it doesn't work. i just want to check if my KeyString belongs to Sentence, that's all. basically i store into Sentence the value of a cell. thx Maileen |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
thanks a lot,
it works great. :) Maileen Jim Thomlinson wrote: Try using the instr function. It returns the location of the beginning of one text string withing another. If the string is not found it returns zero. HTH "Maileen" wrote: Hi, I would like to know if a String belongs to another string. for example : Dim KeyString as String Dim Sentence as String Dim Result as Interger Result = worksheetFunction.Find(KeyString,Sentence) if (Result<"") then Msgbox "KeyString exists within Senetence" EndIf but it doesn't work. i just want to check if my KeyString belongs to Sentence, that's all. basically i store into Sentence the value of a cell. thx Maileen |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
WorksheetFunction is an application object.
Try: Sub test() Dim KeyString As String Dim Sentence As String Dim Result As String KeyString = "AAAA" Sentence = "BBBB CCCC AAAA NNNN" Result = Application.WorksheetFunction.Find(KeyString, Sentance) If (Result < "") Then MsgBox "KeyString exists within Senetence" End If End Sub Cheers, Allan P. London, CPA "Maileen" wrote in message ... Hi, I would like to know if a String belongs to another string. for example : Dim KeyString as String Dim Sentence as String Dim Result as Interger Result = worksheetFunction.Find(KeyString,Sentence) if (Result<"") then Msgbox "KeyString exists within Senetence" EndIf but it doesn't work. i just want to check if my KeyString belongs to Sentence, that's all. basically i store into Sentence the value of a cell. thx Maileen |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Your code will work if the string is found, but if not, it raises an error.
Instr as suggested by Jim Thomlinson would seem a better choice. -- Regards, Tom Ogilvy "alondon" wrote in message ... WorksheetFunction is an application object. Try: Sub test() Dim KeyString As String Dim Sentence As String Dim Result As String KeyString = "AAAA" Sentence = "BBBB CCCC AAAA NNNN" Result = Application.WorksheetFunction.Find(KeyString, Sentance) If (Result < "") Then MsgBox "KeyString exists within Senetence" End If End Sub Cheers, Allan P. London, CPA "Maileen" wrote in message ... Hi, I would like to know if a String belongs to another string. for example : Dim KeyString as String Dim Sentence as String Dim Result as Interger Result = worksheetFunction.Find(KeyString,Sentence) if (Result<"") then Msgbox "KeyString exists within Senetence" EndIf but it doesn't work. i just want to check if my KeyString belongs to Sentence, that's all. basically i store into Sentence the value of a cell. thx Maileen |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Find String in another string - only between spaces | Excel Worksheet Functions | |||
Find Many String options in ONE String | Excel Worksheet Functions | |||
find string within other string | Excel Worksheet Functions | |||
to search for a string and affect data if it finds the string? | Excel Worksheet Functions | |||
find a string inside another string | Excel Programming |