Design & Development

VBA 정규식 3탄

셀값 중 한글이 포함되어 있는지 확인. 다국어 포함되면 무용지물이지만 영한(특수문자 포함) 혼용 데이타에서는 그럭저럭 작동 ^^;

Option Explicit
Sub ChkKor()

   Dim RegEx      As VBScript_RegExp_55.RegExp
   Dim Myrange As Range, C As Range

   Set RegEx = New VBScript_RegExp_55.RegExp
   Set Myrange = ActiveSheet.Range("B2:" & Range("B2").End(xlDown).Address)

   With RegEx
      .MultiLine = False
      .Global = False
      .IgnoreCase = True
      '--  .Pattern = "[^w%&+-,""""./@!#$()''*:;?[]^_`{|}~]+"   // 11.23일
      .Pattern = "[ㄱ-ㅎ가-힣]"
   End With

   For Each C In Myrange
      C.Offset(0, 1) = RegEx.Test(C)
   Next

   Set Myrange = Nothing
   Set RegEx = Nothing

End Sub

수정 : 한글 패턴은 “[ㄱ-ㅎ가-힣]” 이렇게 해주는게 훨씬 깔끔하겠네요.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s