VBA计算文本出现的次数

时间:2016-07-15 14:40:41

标签: excel-vba vba excel

我尝试使用公式计算从D1到Dj出现“s”的次数,但我一直收到错误

nS = Application.WorksheetFunction.CountIf(Worksheets(i).Range(Cells(1, 4)

主题就像

 Public Sub check()
                Dim nS As Integer
                Dim j As Integer
                Dim Row_Count As Integer
                Dim i As Integer
                j = Row_Count + 53
                nS = Application.WorksheetFunction.CountIf(Worksheets(i).Range(Cells(1, 4), Cells(j, 4)), "s")
                MsgBox "nS=" & nS
                MsgBox "D" & j
End Sub

第一个MsgBox一直显示nS = 0

1 个答案:

答案 0 :(得分:0)

>>> timeit.timeit(f1, number=10000) 3.640433839719143 >>> timeit.timeit(f2, number=10000) 3.6921612171574765 集合从1开始,但在您的情况下Worksheets为0