-
[정규식] 숫자를 한글로 변환VB(A) 2018. 2. 23. 20:30
위와 같이 숫자를 한글로 바꿔주는 사용자 정의 함수.
정규식을 이용하여 숫자만 추출한 뒤 한글로 변환하였다.
두가지 버전의 함수가 있고 개인적으로는 두번째 함수가 마음에 드는 편.
정규식의 replace 를 이용해 한번에 바꾸고 싶었는데, 구글링을 통해서도 그런 방법은 찾지 못해 결국 순환문을 사용
Option ExplicitFunction ConvertKorean(tmp As String) As StringWith CreateObject("vbscript.regexp").Global = False.Pattern = "(\d+)"DoIf .test(tmp) = False Then Exit Dotmp = .Replace(tmp, Application.Evaluate("numberstring(" & .Execute(tmp)(0) & ",1)"))LoopEnd WithConvertKorean = tmpEnd FunctionFunction ConvertKorean2(tmp As String) As StringDim Matches As ObjectDim i As IntegerWith CreateObject("vbscript.regexp").Global = True.Pattern = "(\d+)"Set Matches = .Execute(tmp)If .test(tmp) = True ThenFor i = 1 To Matches.Counttmp = Replace(tmp, Matches(i - 1), WorksheetFunction.Text(Matches(i - 1), "[dbnum4]"), Count:=1)NextEnd IfEnd WithConvertKorean2 = tmpEnd Functioncs 'VB(A)' 카테고리의 다른 글
데이터를 셀별로 나누기 (0) 2019.01.17 [추가기능] 주소변환(지번주소, 도로명주소, 우편번호) (2) 2018.06.22 도로명주소 가져오기 (0) 2018.02.13 여러 시트를 쉽게 이동하기 (0) 2018.01.05 [정규식] 텍스트 파일을 조건에 맞게 쪼개서 가져오기 (0) 2017.12.31 댓글