Closed Thread
Results 1 to 8 of 8

Substring check within VBA

  1. #1
    Gary's Student
    Guest

    Substring check within VBA

    If Str1 and Str2 are strings, is there a function or simple coding within VBA
    to return TRUE if Str1 is a substring of Str2, otherwise FALSE?

    Thanks in advance
    --
    Gary's Student

  2. #2
    Norman Jones
    Guest

    Re: Substring check within VBA

    Hi Gary's Sudent,

    For xl2k ==> look at the InStr function in VBA help.


    BTW, Why does Gary never give you an answer?

    ---
    Regards,
    Norman



    "Gary's Student" <[email protected]> wrote in message
    news:[email protected]...
    > If Str1 and Str2 are strings, is there a function or simple coding within
    > VBA
    > to return TRUE if Str1 is a substring of Str2, otherwise FALSE?
    >
    > Thanks in advance
    > --
    > Gary's Student




  3. #3
    JE McGimpsey
    Guest

    Re: Substring check within VBA

    One way:

    Dim bSubString As Boolean
    bSubString = InStr(Str2, Str1) > 0


    In article <[email protected]>,
    "Gary's Student" <[email protected]> wrote:

    > If Str1 and Str2 are strings, is there a function or simple coding within VBA
    > to return TRUE if Str1 is a substring of Str2, otherwise FALSE?
    >
    > Thanks in advance


  4. #4
    Dave Peterson
    Guest

    Re: Substring check within VBA

    Look at InStr() in VBA or even Like

    if instr(1,str2,str1,vbtextcompare) > 0
    or
    if lcase(str2) like "*" & lcase(str1) & "*" then

    I think I got my str1's and str2's correct--but you'll soon find out!

    (And I made it so upper/lower case didn't matter.)



    Gary's Student wrote:
    >
    > If Str1 and Str2 are strings, is there a function or simple coding within VBA
    > to return TRUE if Str1 is a substring of Str2, otherwise FALSE?
    >
    > Thanks in advance
    > --
    > Gary's Student


    --

    Dave Peterson

  5. #5
    Gary's Student
    Guest

    Re: Substring check within VBA

    Thank you both very much.

    Norman: Gary does give me many answers. He does not function 24/7. The
    individuals that support this forum are razor-sharp and lightning-fast.

    Perhaps I should change my name to Forum's Student.
    --
    Gary's Student


    "Norman Jones" wrote:

    > Hi Gary's Sudent,
    >
    > For xl2k ==> look at the InStr function in VBA help.
    >
    >
    > BTW, Why does Gary never give you an answer?
    >
    > ---
    > Regards,
    > Norman
    >
    >
    >
    > "Gary's Student" <[email protected]> wrote in message
    > news:[email protected]...
    > > If Str1 and Str2 are strings, is there a function or simple coding within
    > > VBA
    > > to return TRUE if Str1 is a substring of Str2, otherwise FALSE?
    > >
    > > Thanks in advance
    > > --
    > > Gary's Student

    >
    >
    >


  6. #6
    Dave Peterson
    Guest

    Re: Substring check within VBA

    I think InStr has been there for a long time (forever??).

    I bet you were warning about instrrev???



    Norman Jones wrote:
    >
    > Hi Gary's Sudent,
    >
    > For xl2k ==> look at the InStr function in VBA help.
    >
    > BTW, Why does Gary never give you an answer?
    >
    > ---
    > Regards,
    > Norman
    >
    > "Gary's Student" <[email protected]> wrote in message
    > news:[email protected]...
    > > If Str1 and Str2 are strings, is there a function or simple coding within
    > > VBA
    > > to return TRUE if Str1 is a substring of Str2, otherwise FALSE?
    > >
    > > Thanks in advance
    > > --
    > > Gary's Student


    --

    Dave Peterson

  7. #7
    Bob Phillips
    Guest

    Re: Substring check within VBA

    You can also use

    If str2 like "*" & str1 & "*" Then
    ....

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Gary's Student" <[email protected]> wrote in message
    news:[email protected]...
    > If Str1 and Str2 are strings, is there a function or simple coding within

    VBA
    > to return TRUE if Str1 is a substring of Str2, otherwise FALSE?
    >
    > Thanks in advance
    > --
    > Gary's Student




  8. #8
    Norman Jones
    Guest

    Re: Substring check within VBA

    Hi Dave,

    > I bet you were warning about instrrev???


    Yes, I was Dave!

    Thanks for the correction.

    ---
    Regards,
    Norman



    "Dave Peterson" <[email protected]> wrote in message
    news:[email protected]...
    >I think InStr has been there for a long time (forever??).
    >
    > I bet you were warning about instrrev???
    >
    >
    >
    > Norman Jones wrote:
    >>
    >> Hi Gary's Sudent,
    >>
    >> For xl2k ==> look at the InStr function in VBA help.
    >>
    >> BTW, Why does Gary never give you an answer?
    >>
    >> ---
    >> Regards,
    >> Norman
    >>
    >> "Gary's Student" <[email protected]> wrote in
    >> message
    >> news:[email protected]...
    >> > If Str1 and Str2 are strings, is there a function or simple coding
    >> > within
    >> > VBA
    >> > to return TRUE if Str1 is a substring of Str2, otherwise FALSE?
    >> >
    >> > Thanks in advance
    >> > --
    >> > Gary's Student

    >
    > --
    >
    > Dave Peterson




Closed 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