Sub StringAlong()
sArray = Split("alpha,beta,gamma,delta,zeta,eta,theta", ",")
sample = "mm"
For i = LBound(sArray) To UBound(sArray)
If InStr(sArray(i), sample) > 0 Then
MsgBox ("found it")
Exit Sub
End If
Next
MsgBox ("did not find it")
End Sub
--
Gary''s Student - gsnu200837
"SteveDB1" wrote:
> Hello.
>
> Ok, I've been able to further reduce what I want to the following statement.
>
> I have a single string.
>
> I need to compare that string to an array of strings.
>
> If I find my single string in that array, I want to perform task A.
>
> Else, task B.
>
> So, my question is:
>
> 1- how do I populate that array so I have something for comparison?
>
> 2- I thought that I could use an if statement, with Like. Is this correct?
>
> Thank you.
Suppose you have strings to populate the array in A1:A10.
To compare the single string with the strings in the array, you have to loop
through the array.
See my example.
Sub aaa()
Dim MyArray(1 To 10) As String
Dim InArray As Boolean
Dim SingleString As String
SingleString = "Test"
For r = 1 To 10
MyArray(r) = Cells(r, 1).Value
Next
For r = 1 To 10
If SingleString = MyArray(r) Then
InArray = True
End If
Next
If InArray Then
msg = MsgBox(SingleString & " is found in MyArray")
End If
Regards,
Per
End Sub
"SteveDB1" <Stev...@discussions.microsoft.com> skrev i meddelelsen
news:2BB31666-4172-4D3E...@microsoft.com...
Sub StringAlong()
sArray = Split("alpha,beta,gamma,delta,zeta,eta,theta", ",")
Sample = "mm"
If UBound(Filter(sArray, Sample)) >= 0 Then
MsgBox ("found it")
Else
MsgBox ("did not find it")
End If
End Sub
--
Rick (MVP - Excel)
"Gary''s Student" <GarysS...@discussions.microsoft.com> wrote in message
news:21AB1C7F-8ACC-448E...@microsoft.com...