如果function为单元格内容

我试图检查,如果某一范围的内容是真的,它将执行一个function。

With Sheets(1).[A1:A95] If .Cells.Value = "text" Then 'Perform function End If End With 

但是我得到一个types不匹配的错误。 请帮助。

如果您正在尝试检查范围内的每个单元格,然后尝试这种方法。

 Dim cCell As Range For Each cCell in Sheets(1).Range("$A$1:$A$95") 'To test to ensure cCell.Value is what you expect(can remove once working) Debug.Print cCell.Value If cCell.Value ="whateveryouwanttotestfor" Then 'Call your function here Call myFunction End If Next cCell 

为了testingcCell的多个值,使用Select Case

 For Each cCell in Sheets(1).Range("$A$1:$A$95") Select Case cCell.Value Case "text1" Call text1Function Case "text2" Call text2Function 'Do the rest that you need End Select Next cCell