Yes...

By Onur Tosyali

Excel: Count characters in a text (say parantheses of an Access sql)

paste the sql into an excel file in A1
run the macro:


Sub subsub()
Dim a As String
a = ActiveSheet.Cells(1, 1).Value2
' ActiveSheet.Cells(1, 2).Value2 = a
b = 0
c = 0
For ii = 1 To Len(a) + 2
If Mid(a, ii, 1) = "(" Then
b = b + 1
End If
If Mid(a, ii, 1) = ")" Then
c = c + 1
End If
Next ii
MsgBox "Result: " & b & " and" & c
End Sub

This will count paranthesis. For counting something else, change accordingly.

No comments:

Post a Comment