Created
October 1, 2016 20:13
-
-
Save ken-itakura/039f51f82755a07a835265fe9a85ada8 to your computer and use it in GitHub Desktop.
Excel function that checks whether a cell contains Hiragana only or Katakana only
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Function IsAllHiragana(cell) | |
Set REG = CreateObject("VBScript.RegExp") | |
REG.Pattern = "^[ぁ-んー]+$" ' there are a couple of more hiragana in unicode, which are ignored | |
Set REGMatch = REG.Execute(cell) | |
If REGMatch.Count > 0 Then | |
IsAllHiragana = True | |
Else | |
IsAllHiragana = False | |
End If | |
End Function | |
Public Function IsAllKatakana(cell) | |
Set REG = CreateObject("VBScript.RegExp") | |
REG.Pattern = "^[ァ-ヶー]+$" ' there are a couple of more katakana in unicode, which are ignored | |
Set REGMatch = REG.Execute(cell) | |
If REGMatch.Count > 0 Then | |
IsAllKatakana = True | |
Else | |
IsAllKatakana = False | |
End If | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this!
I made a version with the following changes.
Changed IsAllHiragana:
REG.Pattern = "^[" & ChrW(&H3040) & "-" & ChrW(&H309F) & "]+$" ' Match against Unicode range U+3040–U+309F
Changed IsAllKatakana:
REG.Pattern = "^[" & ChrW(&H30A0) & "-" & ChrW(&H30FF) & "]+$" ' Match against Unicode range U+30A0–U+30FF
Added IsAllKanji:
REG.Pattern = "^[" & ChrW(&H4E00) & "-" & ChrW(&H9FBF) & "]+$" ' Match against Unicode range U+4E00–U+9FBF