functionj countchar(str as string,char as string) as long
dim i as long
dim j as long
for i=1 to len(str)
if mid(str,i,1)=char then
j=j+1
end if
next
countchar=j
end function

解决方案 »

  1.   

    Private Sub Command1_Click()
    VBA.MsgBox GetRepeatCount("aa aa aa jjsajdlka", "aa")
    End Sub
    Public Function GetRepeatCount(S As String, Find As String) As Long
    GetRepeatCount = (VBA.Len(S) - VBA.Len(VBA.Replace(S, Find, ""))) \ VBA.Len(Find)
    End Function
      

  2.   

    functionj countchar(str as string,char as string) as long
    dim i as long
    dim j as long
    for i=1 to len(str)
    if mid(str,i,1)=char then
    j=j+1
    end if
    next
    countchar=j
    end function
    这样的方法很好
      

  3.   

    用Filter函数,看返回值!
      

  4.   

    这种问题应该自个儿写吧!
    如下:
        q=0
        m=len(字符串)
        for i=1 to m
           if mid(字符串,i,1)="A" and mid(字符串,i+1,1)="A" then
           q=q+1   (q即为"AA"的个数) 
           end if
        next i