function inArray(str,arr)
inArray=false
if not isnull(arr) and isarray(arr) then
for ii=0 to ubound(arr)
if ucase(trim(arr(ii)))=ucase(trim(str)) then
inArray=true
exit function
end if
next
end if
end function
使用
arr= Array("Jan","Feb","Mar","Apr","Sep","Oct", "Nov","Dec")
inArray("Feb",arr) output true
inArray("May",arr) output false
本文介绍了一种在VBA中检查字符串是否存在于数组中的方法。通过使用自定义函数inArray,可以有效地判断指定字符串是否为数组元素之一。该函数首先验证输入数组的有效性,然后遍历数组比较每个元素,实现大小写不敏感的字符串匹配。

228

被折叠的 条评论
为什么被折叠?



