マクロ処理になります。 ずっと前に遊びで作ってみたものですので決してスマートな表現ではありませんが、参考になればと 思います。
[Alt]を押しながら[F11]を押すと Visual Basic Editor が起動しますので、標準モジュールを挿入し、 以下をコピーしてから Visual Basic Editor を閉じます。 =ENGNB(A1) の形式で使用すると、9012 → Nine thousand twelve のように英語で表記します。 処理可能なデータは半角数字のみが入力されているセルで、それ以外は正しく表記されません。
Function ENGNB(DT) Dim LL As Integer, EN As String, BLK As String, DumDT As String, _ PP As Integer, P As Integer, Unit As String LL = Len(DT) EN = "" BLK = "" DumDT = "" ENGNB = "" DumDT = Application.WorksheetFunction.Rept("*", 15 - LL) & DT For PP = 1 To 5 BLK = Mid(DumDT, ((PP - 1) * 3) + 1, 3) For P = 1 To 3 If BLK = "***" Then Exit For Select Case P Case Is = 1, 3 Select Case Mid(BLK, P, 1) Case Is = "0" EN = "" Case Is = 1 EN = "one" Case Is = 2 EN = "two" Case Is = 3 EN = "three" Case Is = 4 EN = "four" Case Is = 5 EN = "five" Case Is = 6 EN = "six" Case Is = 7 EN = "seven" Case Is = 8 EN = "eight" Case Is = 9 EN = "nine" Case Else '"*" EN = "" End Select ENGNB = RTrim(ENGNB & " " & EN) If P = 1 Then If EN <> "" Then ENGNB = RTrim(ENGNB & " " & "hundred ") End If Case Else Select Case Mid(BLK, P, 1) Case Is = "0" EN = "" Case Is = 1 Select Case Mid(BLK, 3, 1) Case Is = 1 EN = "eleven" Case Is = 2 EN = "twelve" Case Is = 3 EN = "thirteen" Case Is = 4 EN = "fourteen" Case Is = 5 EN = "fifteen" Case Is = 6 EN = "sixteen" Case Is = 7 EN = "seventeen" Case Is = 8 EN = "eighteen" Case Is = 9 EN = "nineteen" Case Is = "0" EN = "ten" Case Else '"*" EN = "" End Select ENGNB = RTrim(ENGNB & " " & EN) Exit For Case Is = 2 EN = "twenty" Case Is = 3 EN = "thirty" Case Is = 4 EN = "fourty" Case Is = 5 EN = "fifty" Case Is = 6 EN = "sixty" Case Is = 7 EN = "seventy" Case Is = 8 EN = "eighty" Case Is = 9 EN = "ninety" Case Else '"*" EN = "" End Select ENGNB = RTrim(ENGNB & " " & EN) End Select Next P Select Case PP Case Is = 1 Unit = "trillion " Case Is = 2 Unit = "billion " Case Is = 3 Unit = "million " Case Is = 4 Unit = "thousand " Case Else Unit = "" End Select Select Case BLK Case Is = "***", Is = "000" ENGNB = ENGNB & "" Case Else ENGNB = ENGNB & " " & Unit End Select ENGNB = RTrim(LTrim(ENGNB)) Next PP ENGNB = UCase(Mid(ENGNB, 1, 1)) & Mid(ENGNB, 2, Len(ENGNB) - 1) End Function
この記事にはVBAのコードが含まれています。
緑の太文字→注釈 茶色の太文字→条件分岐 赤の太文字→ループ 青の太文字→その他
++++++++++++++++++++ OS ⇒Windows 98 Version⇒Excel 2000 ++++++++++++++++++++ |