我试图检查,如果某一范围的内容是真的,它会执行一个功能。如果功能的单元格内容
With Sheets(1).[A1:A95]
If .Cells.Value = "text" Then
'Perform function
End If
End With
但是我得到一个类型不匹配错误。请帮助。
我试图检查,如果某一范围的内容是真的,它会执行一个功能。如果功能的单元格内容
With Sheets(1).[A1:A95]
If .Cells.Value = "text" Then
'Perform function
End If
End With
但是我得到一个类型不匹配错误。请帮助。
如果您试图检查范围内的每个单元格,然后尝试使用这种方法。
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
为了测试CCELL的多个值使用选择案例
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
你检查,如果在该范围内的任何单元有搜索词'“文本”'? –
@SiddharthRout:我有7个文本需要在特定范围内检查,每个文本都有一个特定的函数来调用。 – Marco
查看我发布的答案 –