<p><strong>Doublon possible :</strong></p>
<p><a href="https://stackoverflow.com/questions/10951687/how-to-search-for-string-in-ms-access-vba-array" rel="noopener nofollow ugc">How to search for string in MS Access VBA array</a></p>
<p>Je travaille actuellement sur une macro Excel, et je n’ai pas trouvé de moyen de faire comme<br>
<code>if array.contains(mystring)</code></p>
<p>J’ai écrit ce qui suit, et cela me donne le message “Invalid Qualifier” et surligne le <code>Mainfram</code> juste après <code>If</code></p>
<pre><code class="lang-auto">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
</code></pre>
<p>La sélection est une colonne.</p>
<p>Quelqu’un peut-il m’aider ?</p>
<p>Bonjour, JP<br>
J’ai essayé votre suggestion, et cela a dit Object required. Et a surligné le<br>
<em><strong>If IsInArray(cell.Text, Mainfram) Then</strong></em><br>
Voici mon code complet :</p>
<pre><code class="lang-auto">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
</code></pre>
<p>Peu importe, j’ai trouvé cette erreur stupide…<br>
Merci quand même.</p>
<hr>
<p><em>Source : <a href="https://stackoverflow.com/questions/10951687/how-to-search-for-string-in-ms-access-vba-array" rel="noopener nofollow ugc">Stack Overflow</a></em></p>