2013-11-01 55 views
2

我正在使用以下代码来搜索工作表以找出单词“示例”出现的次数。Excel VBA使用范围选择整个工作表

count = Application.WorksheetFunction.CountIf(Range("A1:A10"), "example") 

我似乎无法弄清楚如何使用Range函数遍历整个工作表。

回答

1

请尝试在下面查找整个表单中的字符串“示例”。

Count = Application.WorksheetFunction.CountIf(Cells, "example")

使用通配符

Count = Application.WorksheetFunction.CountIf(Cells, "*example*")

+0

你是真棒!谢谢你的工作 – user2946105

+0

@ user2946105这是我的荣幸:) – Santosh

3

为什么你需要在整个表进行迭代?你可以改变扩展范围?

A1:A10

count = Application.WorksheetFunction.CountIf(Range("A1:A10"), "example") 

A1:E10

count = Application.WorksheetFunction.CountIf(Range("A1:E10"), "example") 

整页

count = Application.WorksheetFunction.CountIf(ActiveSheet.Cells, "example") 
+0

烨感谢它的作品。 – user2946105