Consulting

Results 1 to 3 of 3

Thread: match variable with list

  1. #1
    VBAX Tutor
    Joined
    Jan 2008
    Posts
    266
    Location

    match variable with list

    i have a variable called cellvalue that i want to match with a list.

    my "betaversion" i use today is :
    if cellvalue like xx or cellvalue like xy or cellvalue like xz... and so on..
    as you might understand this is not a good way of doing it.

    if i put all the values in a sheet can i match them without making a loop.
    i understand that i can do like:

    [VBA]
    x=1
    while x < LastRow
    if cellvalue Like Sheet("List").Range("A" & x).Value Then
    ...do stuff...
    end if
    x= x+1
    wend
    [/VBA]

    but loops is not very efficient.
    what could i do instead?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,443
    Location
    I think this is what you mean

    [vba]

    If Not IsError(Application.Match(cellvalue, Sheet("List").Range("A1").Resize(LastRow),0)) Then
    '... do stuff...
    End If
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Tutor
    Joined
    Jan 2008
    Posts
    266
    Location
    its very close to working.

    the list im matching agains contains something like:

    88.233.2.*
    85.97.87.*
    85.97.86.*

    and cellvalue is complete IPs.
    the way it is now it only does exact matches. if i change the 0 to a 1 it seems it matches every smal part of the value.

    i want it to do wildcardmatch but not completely wild.

Posting Permissions

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