'NUMBERSTRING 関数で作成した漢数字を数値に変換する関数 Function StringNumber(ByVal 漢数字 As String) Dim s As String Dim n As Double, n1 As Double, n2 As Double, n3 As Double Dim i As Long, j As Long Const KANJI = "〇一二三四五六七八九壱弐参伍十百千万億兆拾阡萬" Dim NARRAY As Variant NARRAY = Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 5, 10, 100, _ 1000, 10000, 100000000, 1000000000000#, 10, 1000, 10000) s = 漢数字 For i = 1 To Len(s) j = InStr(1, KANJI, Mid$(s, i, 1), 0) If j = 0 Then StringNumber = CVErr(xlErrNum): Exit Function n = NARRAY(j - 1) If n < 10 Then n1 = n1 * 10 + n ElseIf n < 10000 Then If n1 = 0 Then n2 = n2 + n Else n2 = n2 + n1 * n n1 = 0 Else n3 = n3 + (n2 + n1) * n n2 = 0: n1 = 0 End If Next StringNumber = n3 + n2 + n1 End Function 'NUMBERSTRING 関数と TEXT 関数で作成した漢数字を数値に変換する関数 Function StringNumber2(ByVal 漢数字 As String) Dim s As String Dim n As Double, n1 As Double, n2 As Double, n3 As Double Dim i As Long, j As Long, g As Long Const KANJI = "〇一二三四五六七八九壱弐参伍十百千万億兆拾阡萬01234567890123456789" Dim NARRAY As Variant NARRAY = Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 5, 10, 100, 1000, _ 10000, 100000000, 1000000000000#, 10, 1000, 10000, _ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9) s = Trim$(漢数字) Select Case Left$(s, 1) Case "-", "−" g = -1 s = Mid$(s, 2) End Select For i = 1 To Len(s) j = InStr(1, KANJI, Mid$(s, i, 1), 0) If j = 0 Then StringNumber2 = CVErr(xlErrNum): Exit Function n = NARRAY(j - 1) If n < 10 Then n1 = n1 * 10 + n ElseIf n < 10000 Then If n1 = 0 Then n2 = n2 + n Else n2 = n2 + n1 * n n1 = 0 Else n3 = n3 + (n2 + n1) * n n2 = 0: n1 = 0 End If Next n3 = n3 + n2 + n1 If g = -1 Then n3 = n3 * -1 StringNumber2 = n3 End Function '数字を漢数字に変換する関数 Function Num2Kanji(ByVal number_string As String) As String Const KANJI = "〇一二三四五六七八九" Const NUM = "0123456789" Dim i As Long, j As Long For i = 1 To Len(number_string) j = InStr(1, NUM, Mid$(number_string, i, 1), 0) If j > 0 Then Mid(number_string, i, 1) = Mid$(KANJI, j, 1) Next Num2Kanji = number_string End Function '漢数字を数字に変換する関数 Function Kanji2Num(ByVal kanji_number As String) As String Const KANJI = "〇一二三四五六七八九" Dim i As Long, j As Long For i = 1 To Len(kanji_number) j = InStr(1, KANJI, Mid$(kanji_number, i, 1), 0) If j > 0 Then Mid(kanji_number, i, 1) = CStr(j - 1) Next Kanji2Num = kanji_number End Function