Monday, January 17, 2011

오래간만에 짜본 엑셀 VBA 스크립트


오래간만에 필요에 의해서 작성한 VBA 스크립트..
간단하게..특정 문자열에서 특정 문자가 몇 개나 나오는지를 카운트하는 소스..

Function countchar(src As String, ch As String) As Integer
Dim count As Integer
Dim findIndex As Integer

findIndex = InStr(src, ch)
count = 0

If Len (src) > 0 Then
count = 1
If findIndex > 0 Then
Do While findIndex > 0
count = count + 1
findIndex = InStr(findIndex + 1, src, ch)
Loop
End If
End if

countchar = count
End Function

오래간만이라 그런지 do while 문법도 제대로 기억나지 않았다는거..-_-;;

No comments: