简体   繁体   中英

Excel VBA select entire sheet using Range

I am using the following code to search through a sheet to find out how many times does the word 'example' appear.

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

I can't seem to figure out how to iterate through the entire sheet using the Range function.

Why do you need to iterate through the entire sheet? You can just change the extend the range?

A1:A10

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

A1:E10

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

Entire sheet

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

Try below to look for string "example" in entire sheet.

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

using wildcards

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM