+ Reply to Thread
Results 1 to 3 of 3

Assigning Strings To An Array

Hybrid View

CrazyFileMaker Assigning Strings To An Array 04-22-2009, 01:51 AM
DonkeyOte Re: Assigning Strings To An... 04-22-2009, 02:18 AM
CrazyFileMaker Re: Assigning Strings To An... 04-22-2009, 02:31 AM
  1. #1
    Registered User
    Join Date
    03-31-2009
    Location
    Auburn Alabama
    MS-Off Ver
    Microsoft Office Excel 2007 (Windows)
    Posts
    99

    Thumbs up Assigning Strings To An Array

    Hello,

    My question is about assigning strings to an array.

    The following code searches a cell for three strings (said, told, asked):
    If InStr(Cells(1,1).Value, "said") > 0 Or _
       InStr(Cells(1,1).Value, "told") > 0 Or _
       InStr(Cells(1,1).Value, "asked") > 0 Then
    That works fine and all. But I have a lot more than three strings to search for...

    So, my question is, is there a way to assign those three words to an array, so that each word is an element, and then check for the elements of the array in a string. My guess is it would look something like this:
    If InStr(Cells(1,1).Value, Verb(2)) > 0 Then
    Is something like that possible? How would I code that?

    I'm just looking to be efficient and save myself a lot of unnecessary typing.

    Thanks for any and all help!
    Last edited by CrazyFileMaker; 04-22-2009 at 02:36 AM.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Assigning Strings To An Array

    Something like ?

    Public Sub Example()
    Dim vCrit, vSearch, bCrit As Byte
    vCrit = Array("said", "told", "asked")
    For bCrit = LBound(vCrit) To UBound(vCrit)
        If IsNumeric(Application.Search(vCrit(bCrit), Cells(1, 1).Value)) Then
            MsgBox "a"
            Exit For
        End If
    Next bCrit
    End Sub
    It would of course make most sense to store these words in a range on a sheet... you could then perhaps also think about using Evaluate.

    There may well be other solutions (regex for ex.) ... the above is just one approach.

  3. #3
    Registered User
    Join Date
    03-31-2009
    Location
    Auburn Alabama
    MS-Off Ver
    Microsoft Office Excel 2007 (Windows)
    Posts
    99

    Re: Assigning Strings To An Array

    Thanks Donkey! You always provide me very helpful answers

+ 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