Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Test if cell value is in an array

I want to find out if the contents of a cell are in a predetermined
list. I don't want to have to keep writing an "If" statement for each
entry in the list.

Example:

Array = (Apples, oranges, grapes, bananas}

I want to measure the contents of the cell to determine if they are in
my array. If yes, put a 1, if no put 0. (Will sum 1s later for totals)


I know there's a relatively simple way to do this, but I can't seem to
grasp it right now.

Thanks in advance for any help you can provide!!
Rita

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Test if cell value is in an array

How about:

Function within(r As Range) As Integer
within = 0
s = Array("Apples", "oranges", "grapes", "bananas")
v = r.Value
For i = 0 To 3
If v = s(i) Then
within = 1
End If
Next
End Function


--
Gary''s Student - gsnu200842


"Rita Brasher" wrote:

I want to find out if the contents of a cell are in a predetermined
list. I don't want to have to keep writing an "If" statement for each
entry in the list.

Example:

Array = (Apples, oranges, grapes, bananas}

I want to measure the contents of the cell to determine if they are in
my array. If yes, put a 1, if no put 0. (Will sum 1s later for totals)


I know there's a relatively simple way to do this, but I can't seem to
grasp it right now.

Thanks in advance for any help you can provide!!
Rita


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
Test if Worksheet is not in an Array scott Excel Programming 4 August 13th 07 10:10 PM
Test Initialization of an Array Neal Zimm Excel Programming 7 December 27th 06 04:58 PM
Test for dups in Array Perico[_2_] Excel Programming 5 July 14th 05 09:51 AM
Array Test VBA Dabbler[_2_] Excel Programming 9 March 30th 05 09:53 PM
Test for end of array of objects? peter Excel Programming 8 February 3rd 05 09:15 AM


All times are GMT +1. The time now is 11:31 PM.

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

About Us

"It's about Microsoft Excel"