Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 16
Default If Then else using an Array

Hi All,

I have an array with 29 names held in it, I am wanting to do a if
statement using the content of the Array.

If "MyName" is in ArrayName() Then
Do somthing
else
Do somthing else
End If

I don't know how to go about setting it out.

Can anyone advise?

Many Thanks

Mark
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 4,393
Default If Then else using an Array

=IF(COUNTIF(A1:A100,"MyName")0,"I'm here", "I'm absent")
Just replace A1:A100 by the array name --- but no () please
best wishes
--
Bernard V Liengme
Microsoft Excel MVP
www.stfx.ca/people/bliengme
remove caps from email

"Sh0t2bts" wrote in message
...
Hi All,

I have an array with 29 names held in it, I am wanting to do a if
statement using the content of the Array.

If "MyName" is in ArrayName() Then
Do somthing
else
Do somthing else
End If

I don't know how to go about setting it out.

Can anyone advise?

Many Thanks

Mark



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 16
Default If Then else using an Array

Forgot to mention I am doing this in a Macro, so would need the VBA
version.

ooops Sorry

Mark
  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10,593
Default If Then else using an Array

If Not IsError(Application.Match(some_value, myArray,0)) Then
Do somthing
else
Do somthing else
End If


--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Sh0t2bts" wrote in message
...
Forgot to mention I am doing this in a Macro, so would need the VBA
version.

ooops Sorry

Mark



  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,202
Default If Then else using an Array

You can probably use the Filter function to do your test...

If UBound(Filter(ArrayNames, "MyName")) = 0 Then
' Do something
Else
' Do something else
End If

The above will do an exact case search (so that "rick" would not match
"Rick"). If you need a case insensitive search, you could use this...

If UBound(Filter(ArrayNames, "ue", , vbTextCompare)) = 0 Then

for the If/Then test instead. I don't think you can get any false positives
doing it this way... I mention this because Filter works like InStr and will
find substrings with in the whole text; but that shouldn't matter for the
type of test you described as it will also find the exact match as well as
any substring matches.

Rick



"Sh0t2bts" wrote in message
...
Hi All,

I have an array with 29 names held in it, I am wanting to do a if
statement using the content of the Array.

If "MyName" is in ArrayName() Then
Do somthing
else
Do somthing else
End If

I don't know how to go about setting it out.

Can anyone advise?

Many Thanks

Mark


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
Populate an array that is a subset of a larger array? Jeff Excel Worksheet Functions 1 September 25th 07 12:51 AM
Array: Counting multiple values within array Trilux_nogo Excel Worksheet Functions 4 April 16th 07 03:12 AM
meaning of : IF(Switch; Average(array A, array B); array A) DXAT Excel Worksheet Functions 1 October 24th 06 06:11 PM
combining cells and array from different sheets into an array to pass to IRR() [email protected] Excel Discussion (Misc queries) 3 September 11th 06 07:17 AM
Goal Seek On Members of an Array within Array LostInVBA Excel Worksheet Functions 1 June 27th 05 11:01 PM


All times are GMT +1. The time now is 05:52 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"