I need to develop an UDF for checking a cell value against several possible entries to check whether the cell is equal to any of those values or not. As you see I have an idea regarding how to do this check. But coding the function in a way that can accept multiple optional entries in not clear for me. for instance I am looking something dynamic like CONCATENATE in EXCEL { CONCATENATE( text1, [ text2, ... text_n ] )}. My code for such function with 5 optional argument is as follow:
Function IfAmong(TextToCheck As String, Text1 As String, Optional Text2 As String, _
Optional Text3 As String, Optional Text4 As String, Optional Text5 As String,_
Optional text6 As String) As Boolean
Dim dd As New Scripting.Dictionary
dd.CompareMode = TextCompare
dd.Add Text1, dd.Count
If Text2 <> "" Then dd.Add Text2, dd.Count
If Text3 <> "" Then dd.Add Text3, dd.Count
If Text4 <> "" Then dd.Add Text4, dd.Count
If Text5 <> "" Then dd.Add Text5, dd.Count
If text6 <> "" Then dd.Add text6, dd.Count
IfAmong = dd.Exists(TextToCheck)
dd.RemoveAll
End Function
I want to make it relative to number of optional entries desired by the user (As said like concatenate). and also if possible make the checking of entries automatic through a loop. I tried adding the texts as an array, but not working!
for i =2 to Ubound(text(i))
if text(i) <>"" then..........
next
I was not able to do that as well.
Thanks and regards, M