如果一个数组包含字符串

如果一个数组包含字符串

本文介绍了如何找到,如果一个数组包含字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  How搜索在MS Access VBA数组字符串

我目前工作的一个Excel宏,我无法找到一个方法来做到像
如果array.contains(MyString的)

I am currently working on an Excel macro, and I could not find a way to do likeif array.contains(mystring)

我写了下面的,它给我的信息Invaild资格赛,并突出了 Mainfram 右后如果

I wrote the following, and it gives me the message "Invaild Qualifier" and highlights the 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

的选择是一列

谁能帮助?

JP
我想你的建议,并表示需要对象。和Highlightd的
  如果IsInArray(cell.Text,Mainfram)然后
我的继承人满code

Hi, JPI tried your suggestion, and it said Object required. And Highlightd the If IsInArray(cell.Text, Mainfram) ThenHeres 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 that stupid Error...Thank you anyways

推荐答案

我的回答一个非常类似的问题:

Using the code from my answer to a very similar question:

Sub DoSomething()
Dim Mainfram(4) As String
Dim cell As Excel.Range

Mainfram(0) = "apple"
Mainfram(1) = "pear"
Mainfram(2) = "orange"
Mainfram(3) = "fruit"

For Each cell In Selection
  If IsInArray(cell.Value, MainFram) Then
    Row(cell.Row).Style = "Accent1"
  End If
Next cell

End Sub

Function IsInArray(stringToBeFound As String, arr As Variant) As Boolean
  IsInArray = (UBound(Filter(arr, stringToBeFound)) > -1)
End Function

这篇关于如何找到,如果一个数组包含字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 04:28