使用带有文本字符串的公式填写多个单元格

Ong*_*pen 1 excel vba excel-vba

我想问一下vba excel,我想填写多个单元格的公式,但公式包含文本字符串.

Sub Test()

    Dim strFormulas(1 To 2) As Variant

    With ActiveSheet
        strFormulas(1) = "=ISNUMBER(SEARCH(Apple,B2))"
        strFormulas(2) = "=ISNUMBER(SEARCH(Orange,B2))"

        .Range("C2:D2").Formula = strFormulas
        .Range("C2:D11").FillDown
    End With

End Sub
Run Code Online (Sandbox Code Playgroud)

在第一个我这样做,但因为本地没有文字字符串,所以结果都是假的,因为公式应该是 =ISNUMBER(SEARCH("Apple",B2))

Ros*_*tta 5

strFormulas(1) = "=ISNUMBER(SEARCH(""Apple"",B2))"
strFormulas(2) = "=ISNUMBER(SEARCH(""Orange"",B2))"
Run Code Online (Sandbox Code Playgroud)