+ Reply to Thread
Results 1 to 5 of 5

Find a string into another string

  1. #1
    Maileen
    Guest

    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

  2. #2
    Jim Thomlinson
    Guest

    RE: 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


  3. #3
    Maileen
    Guest

    Re: 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


  4. #4
    alondon
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    > 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. #5
    Tom Ogilvy
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    > 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" <[email protected]> wrote in message
    > news:[email protected]...
    > > 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1