【发布时间】:2017-09-05 07:31:43
【问题描述】:
我以这篇文章为灵感:How to find if an array contains a string
希望大家帮帮我:
我想在 Excel 工作表中逐个单元格地循环遍历列(范围),并查找单元格值是否在也从 Excel 范围归档的数组中,但由于某种原因,我得到了一个类型不匹配错误。我想,这与将数组声明为变体有关,但将其更改为字符串也无济于事。
提前非常感谢,任何帮助都非常感谢
Function IsInArray(stringToBeFound, arr As Variant) As Boolean
IsInArray = (UBound(Filter(arr, stringToBeFound)) > -1)
End Function
Sub Check()
Dim cell As Range
Dim arr() As String
arr = Range("I2:I3").Value
For Each cell In Range("D2:D15")
If IsInArray(CStr(cell.Value), arr) Then
cell.Interior.Color = RGB(0, 176, 80)
Else
cell.Interior.Color = RGB(0, 0, 0)
End If
Next cell
End Sub
【问题讨论】:
标签: arrays excel vba compare range