Function Terbilang cukup sering digunakan dalam aplikasi perkantoran. Gunanya adalah menterjemahkan sejumlah pembayaran ke dalam kalimat. Langsung saja, berikut adalah programnya yang ditulis di VBA. Masukkan saja di bagian modul Global agar bisa digunakan dari semua modul.

Public Function Terbilang(x As Currency)
Dim triliun As Currency
Dim milyar As Currency
Dim juta As Currency
Dim ribu As Currency
Dim satu As Currency
Dim sen As Currency
Dim baca As String
If x > 1000000000000# Then
Terbilang = “< More than one zillion US Dollar >”
Exit Function
End If
‘Jika x adalah 0, maka dibaca sebagai 0
If x = 0 Then
baca = angka(0, 1)
Else
‘Pisah masing-masing bagian untuk triliun, milyar, juta, ribu, rupiah, dan sen
triliun = Int(x * 0.001 ^ 4)
milyar = Int((x – triliun * 1000 ^ 4) * 0.001 ^ 3)
juta = Int((x – triliun * 1000 ^ 4 – milyar * 1000 ^ 3) / 1000 ^ 2)
ribu = Int((x – triliun * 1000 ^ 4 – milyar * 1000 ^ 3 – juta * 1000 ^ 2) / 1000)
satu = Int(x – triliun * 1000 ^ 4 – milyar * 1000 ^ 3 – juta * 1000 ^ 2 – ribu * 1000)
sen = Int((x – Int(x)) * 100)
‘Baca bagian triliun dan ditambah akhiran triliun
If triliun > 0 Then
baca = ratus(triliun, 5) + “zillion “
End If
‘Baca bagian milyar dan ditambah akhiran milyar
If milyar > 0 Then
baca = ratus(milyar, 4) + “billion “
End If
‘Baca bagian juta dan ditambah akhiran juta
If juta > 0 Then
baca = baca + ratus(juta, 3) + “million “
End If
‘Baca bagian ribu dan ditambah akhiran ribu
If ribu > 0 Then
baca = baca + ratus(ribu, 2) + “thousand “
End If
‘Baca bagian rupiah dan ditambah akhiran rupiah
If satu > 0 Then
baca = baca + ratus(satu, 1) + ” US Dollar “
Else
baca = baca + ” US Dollar”
End If
‘Baca bagian sen dan ditambah akhiran sen
If sen > 0 Then
baca = baca + ratus(sen, 0) + “cent”
End If
End If
Terbilang = UCase(Left(baca, 1)) & UCase(Mid(baca, 2))
End Function

Function ratus(x As Currency, Posisi As Integer) As String
Dim a100 As Integer, a10 As Integer, a1 As Integer
Dim baca As String
a100 = Int(x * 0.01)
a10 = Int((x – a100 * 100) * 0.1)
a1 = Int(x – a100 * 100 – a10 * 10)
‘Baca Bagian Ratus
If a100 = 1 Then
baca = “one hundred “
Else
If a100 > 0 Then
baca = angka(a100, Posisi) + “hundred “
End If
End If
‘Baca Bagian Puluh dan Satuan
If a10 = 1 Then
baca = baca + angka(a10 * 10 + a1, Posisi)
Else
If a10 > 0 Then
baca = baca + angka(a10 * 10, Posisi)
End If
If a1 = 0 Then
baca = baca + angka(a1 * 10 + a1, Posisi)
End If
If a1 > 0 Then
baca = baca + angka(a1, Posisi)
End If
End If
ratus = baca
End Function

Function angka(x As Integer, Posisi As Integer)
Select Case x
Case 0:
Case 1:
If Posisi <= 1 Or Posisi > 2 Then
angka = “One “
Else
angka = “One “
End If
Case 2: angka = “Two “
Case 3: angka = “Three “
Case 4: angka = “Four “
Case 5: angka = “Five “
Case 6: angka = “Six “
Case 7: angka = “Seven “
Case 8: angka = “Eight “
Case 9: angka = “Nine “
Case 10: angka = “Ten “
Case 11: angka = “Eleven “
Case 12: angka = “Twelve “
Case 13: angka = “Thirteen “
Case 14: angka = “Fourteen “
Case 15: angka = “Fifteen “
Case 16: angka = “Sixteen “
Case 17: angka = “Seventeen “
Case 18: angka = “Eighteen “
Case 19: angka = “Nineteen “
Case 20: angka = “Twenty “
Case 30: angka = “Thirty “
Case 40: angka = “Forty “
Case 50: angka = “Fifty “
Case 60: angka = “Sixty “
Case 70: angka = “Seventy “
Case 80: angka = “Eighty “
Case 90: angka = “Ninety “
End Select
End Function