adding list to dictionary or array

22strider

Active Member
Joined
Jun 11, 2007
Messages
311
Hello Friends

Is it possible to add values to array or dictionary that can be used as a look up list?
I would like to add following list and later check if certain value starts with values in this list or not.

FP-*
TJ-*
TP-*
WP-*
BR-*
HS-*

I am not sure if adding wild card "*" to the list is a good idea or not.

Thanks
Rajesh
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Rajesh,

One way is to use a delimited string containing what you want to check, and then check to see if the item is in that string or not like so:
Code:
Sub tgr()
    
    Dim strCheck As String
    Dim strTemp As String
    
    strCheck = " FP TJ TP WP BR HS "
    strTemp = "FP-123"
    
    
    If InStr(1, strCheck, " " & Left(strTemp, 2) & " ", vbTextCompare) > 0 Then
        'strTemp was found inside strCheck
        'Do something
        MsgBox "Found!"
    Else
        'strtemp was not found inside strcheck
        MsgBox "Not Found"
    End If
    
End Sub
 
Upvote 0
Hello

Interesting take; I'll give it a try and let you know how it worked. Another bit of complication is that the entries for 'strCheck' don't always have 2 characters. Some are of 1 and 3 characters as well.

Thanks
Rajesh
 
Upvote 0
Question for you; why did you add space " " before and after Left(strTemp, 2)?
in the same line why did you add space before and after entries in 'strCheck'?
My instinct was to compare 'FP-' with first 3 characters of 'strTemp'
 
Upvote 0
That was to avoid partial matches. If you're looking for just "a", it would find a match in "abc", but with the spaces, " a " no longer matches " abc ".

As for the differing lengths, it could probably be worked out, but I'd need some examples. If you want to go the array/dictionary route though, that is also doable, though the code is a bit longer.
 
Upvote 0

Forum statistics

Threads
1,215,471
Messages
6,124,999
Members
449,201
Latest member
Lunzwe73

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top