Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Check if a String is inside an Array

You can use the worksheet function Index:

Option Explicit
Sub testme()

Dim res As Variant
Dim MyArray As Variant

MyArray = Array("Test", "This")

res = Application.Match("this", MyArray, 0)

If IsError(res) Then
MsgBox "Not in there"
Else
MsgBox "It's there and at position: " & res
End If

End Sub


Luis Carrion wrote:

Hi,
If I were to check if a variable: A="Test" is inside a list of
possible strings,I´ll do this:

Dim A as string
Dim B as variant
Dim MyArray As variant

MyArray=Array("Test", "This")
For Each B in MyArray
If A=B then Msgbox "It´s inside the group
Next A

Is it possible to test this in other way; something like this
If A is in/like MyArray then....... ---without looping inside the
array

Thanks.
LC


--

Dave Peterson

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Check if a String is inside an Array

You can use the worksheet function Index:

Did you mean the worksheet function Match?



--
Regards,
Tom Ogilvy

"Dave Peterson" wrote in message
...
You can use the worksheet function Index:

Option Explicit
Sub testme()

Dim res As Variant
Dim MyArray As Variant

MyArray = Array("Test", "This")

res = Application.Match("this", MyArray, 0)

If IsError(res) Then
MsgBox "Not in there"
Else
MsgBox "It's there and at position: " & res
End If

End Sub


Luis Carrion wrote:

Hi,
If I were to check if a variable: A="Test" is inside a list of
possible strings,I´ll do this:

Dim A as string
Dim B as variant
Dim MyArray As variant

MyArray=Array("Test", "This")
For Each B in MyArray
If A=B then Msgbox "It´s inside the group
Next A

Is it possible to test this in other way; something like this
If A is in/like MyArray then....... ---without looping inside the
array

Thanks.
LC


--

Dave Peterson



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default Check if a String is inside an Array

As Tom Ogilvy has pointed out, you meant to refer to the worksheet
function Match.

In xl2000 SR-1 and previous, the code below will work on 1-dimensional
arrays of 5461 or fewer elements.

Alan Beban

Dave Peterson wrote:
You can use the worksheet function Index:

Option Explicit
Sub testme()

Dim res As Variant
Dim MyArray As Variant

MyArray = Array("Test", "This")

res = Application.Match("this", MyArray, 0)

If IsError(res) Then
MsgBox "Not in there"
Else
MsgBox "It's there and at position: " & res
End If

End Sub


Luis Carrion wrote:

Hi,
If I were to check if a variable: A="Test" is inside a list of
possible strings,I´ll do this:

Dim A as string
Dim B as variant
Dim MyArray As variant

MyArray=Array("Test", "This")
For Each B in MyArray
If A=B then Msgbox "It´s inside the group
Next A

Is it possible to test this in other way; something like this
If A is in/like MyArray then....... ---without looping inside the
array

Thanks.
LC




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Check if a String is inside an Array

Yes, I did. Darn fingers.



Tom Ogilvy wrote:

You can use the worksheet function Index:


Did you mean the worksheet function Match?

--
Regards,
Tom Ogilvy

"Dave Peterson" wrote in message
...
You can use the worksheet function Index:

Option Explicit
Sub testme()

Dim res As Variant
Dim MyArray As Variant

MyArray = Array("Test", "This")

res = Application.Match("this", MyArray, 0)

If IsError(res) Then
MsgBox "Not in there"
Else
MsgBox "It's there and at position: " & res
End If

End Sub


Luis Carrion wrote:

Hi,
If I were to check if a variable: A="Test" is inside a list of
possible strings,I´ll do this:

Dim A as string
Dim B as variant
Dim MyArray As variant

MyArray=Array("Test", "This")
For Each B in MyArray
If A=B then Msgbox "It´s inside the group
Next A

Is it possible to test this in other way; something like this
If A is in/like MyArray then....... ---without looping inside the
array

Thanks.
LC


--

Dave Peterson


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check for NON-presence of a string in another string G.P.N.L. c.v.a. Excel Worksheet Functions 4 December 11th 09 06:10 PM
Searching for a string of text inside a column Steve W. Excel Worksheet Functions 5 March 5th 09 04:52 PM
Table Lookup formula where 2 known values are inside array excel-lookuper New Users to Excel 3 May 25th 07 05:49 AM
how can I check for cell focus inside a spreadsheet ? EdwardAlanzo Excel Worksheet Functions 2 May 16th 07 12:41 AM
Need macro to insert text string while inside cell (formula) BrianB Excel Discussion (Misc queries) 0 May 31st 05 03:18 PM


All times are GMT +1. The time now is 06:11 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"