Using Like

  • Thread starter Thread starter AlexS
  • Start date Start date
A

AlexS

I have a string variable 'Group' it could contain any number of say six alpha
characters (i.e. ajmprt, mjtr, rtm ...etc) I want to test whether the string
contains say 'm'

An expression such as

Dim Sample as String, Group as String

Sample = "m"
Group = "rjma"

If Group Like *Sample* then.....

does not work. I am a beginner and have struggled for a week can anyone point
me in the right direction?

AlexS
 
if group like "*" & sample & "*" then
or maybe
if lcase(group) like "*" & lcase(sample) & "*" then
 
Use it like this

If Group Like "*" & Sample & "*" Then MsgBox ""
 
would something like this work?

Sub test()
Dim Sample As String, Group As String
Sample = "m"
Group = "rjma"

If InStr(1, Group, Sample) > 0 Then
MsgBox "Found " & Sample & " at position " & InStr(1, Group, Sample)
Else
MsgBox Sample & " not found"
End If
End Sub
 
Thanks everyone. I had tried * & Group & * but omitted to put the quotes
around the asterisks. Typical beginners error I suspect.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top