If cell values are present in an array

cfdh_edmundo

Board Regular
Joined
Nov 9, 2005
Messages
133
Hi,

I have the following code below which works exactly as I want it to:

Rich (BB code):
If Cells(rowCount, 1).Value = Range("D2").Value And Not IsEmpty(Cells(rowCount, 1).Value) Then
    Cells(rowCount, 14).Font.Color = vbRed
End If


But now I want to the = Range("D2").Value section.


Instead of if statement running when the value equals cell D2, I would like it to run if the value matches any element of the array feeArray().

I've already defined this feeArray() previously and all of the elements are strings.


Any help would be great!

Thanks!
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hi there. I think this will work (not tested):

Code:
<code>
If <code>UBound(Filter(feeArray, <code>Cells(rowCount, 1).Value</code>)) > -1</code> And Not IsEmpty(Cells(rowCount, 1).Value) Then
    Cells(rowCount, 14).Font.Color = vbRed
End If
</code>
 
Upvote 0
Hi Edmundo,

You can use Application.Match to identify the item in your array:

Code:
    Dim Arr(3)
    Dim MatchValue As Long
    
    Arr(0) = "North"
    Arr(1) = "South"
    Arr(2) = "East"
    Arr(3) = "West"
    
    MatchValue = Application.Match("South", Arr, 0)

    If IsNumeric(MatchValue) Then Call MyCode
 
Last edited:
Upvote 0
You haven't said what dimensions feearray has so I assumed one dimension
Code:
If Not IsEmpty(Cells(RowCount, 1).Value) Then
For i = LBound(feearray) To UBound(feearray)
If Cells(RowCount, 1).Value = feearray(i) Then
    Cells(RowCount, 14).Font.Color = vbRed
    Exit For
End If
end if
Next i

Code NOT TESTED
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,779
Messages
6,126,843
Members
449,343
Latest member
DEWS2031

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top