Possible duplicate:
How to search string in MS Access VBA array
I am currently working on an Excel macro and I could not find a way to do this if array.contains(mystring)
I wrote the following and it gives me the message "Invaild Qualifier" and selects Mainfram right after If
Dim Mainfram(4) As String Mainfram(0) = "apple" Mainfram(1) = "pear" Mainfram(2) = "orange" Mainfram(3) = "fruit" For Each cel In Selection If Mainfram.Contains(cel.Text) Then Row(cel.Row).Style = "Accent1" End If Next cel
Selection is a column
Can anybody help?
Hi JP I tried your suggestion and he said an object is required. And highlight If IsInArray (cell.Text, Mainfram) Then Heres my full code
Sub changeRowColor() Columns("B:B").Select Dim cel As Excel.Range Dim Mainfram(4) As String Mainfram(0) = "apple" Mainfram(1) = "pear" Mainfram(2) = "orange" Mainfram(3) = "Banana" For Each cel In Selection If IsInArray(cell.Value, Mainfram) Then Rows(cel.Row).Style = "Accent1" End If Next cel End Sub Function IsInArray(stringToBeFound As String, arr As Variant) As Boolean IsInArray = (UBound(Filter(arr, stringToBeFound)) > -1) End Function
Nevermind, I found this stupid mistake ... Anyway, thanks
substring arrays vba
Nicola-V Jun 19 2018-12-12T00: 00Z
source share