ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Find a string into another string (https://www.excelbanter.com/excel-programming/320980-find-string-into-another-string.html)

Maileen[_3_]

Find a string into another string
 
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

Jim Thomlinson[_3_]

Find a string into another string
 
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


Maileen[_2_]

Find a string into another string
 
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


alondon

Find a string into another string
 
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




Tom Ogilvy

Find a string into another string
 
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







All times are GMT +1. The time now is 05:07 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com