Skip to content

Instantly share code, notes, and snippets.

@ken-itakura
Created October 1, 2016 20:13
Show Gist options
  • Save ken-itakura/039f51f82755a07a835265fe9a85ada8 to your computer and use it in GitHub Desktop.
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
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
@sakoe
Copy link

sakoe commented Feb 17, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment