Advertisement
sohotcall

Terbilang Excel VBA

Feb 22nd, 2021 (edited)
2,155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public Function Terbilang(q As Currency)
  2.     Dim satuan(10) As String
  3.     satuan(0) = "Nol"
  4.     satuan(1) = "Satu"
  5.     satuan(2) = "Dua"
  6.     satuan(3) = "Tiga"
  7.     satuan(4) = "Empat"
  8.     satuan(5) = "Lima"
  9.     satuan(6) = "Enam"
  10.     satuan(7) = "Tujuh"
  11.     satuan(8) = "Delapan"
  12.     satuan(9) = "Sembilan"
  13.     Dim ribuan(5) As String
  14.     ribuan(0) = ""
  15.     ribuan(1) = "Ribu"
  16.     ribuan(2) = "Juta"
  17.     ribuan(3) = "Miliar"
  18.     ribuan(4) = "Triliun"
  19.     Dim x As Currency
  20.     x = Int(q)
  21.     Dim tera As Currency
  22.     tera = Int(q / 1000000000000#)
  23.     Dim giga As Currency
  24.     giga = Int((q - tera * 1000000000000#) / 1000000000)
  25.     Dim mega As Currency
  26.     mega = Int((q - tera * 1000000000000# - giga * 1000000000) / 1000000)
  27.     Dim kilo As Currency
  28.     kilo = Int((q - tera * 1000000000000# - giga * 1000000000 - mega * 1000000) / 1000)
  29.     Dim unit As Currency
  30.     unit = Int((q - tera * 1000000000000# - giga * 1000000000 - mega * 1000000 - kilo * 1000) / 1)
  31.     Dim sen As Currency
  32.     sen = Int((q - Int(q)) * 100)
  33.     Dim arr(5) As Integer
  34.     arr(0) = Int(unit)
  35.     arr(1) = Int(kilo)
  36.     arr(2) = Int(mega)
  37.     arr(3) = Int(giga)
  38.     arr(4) = Int(tera)
  39.     Dim result(5) As String
  40.     result(0) = ""
  41.     result(1) = ""
  42.     result(2) = ""
  43.     result(3) = ""
  44.     result(4) = ""
  45.     Dim k As Integer
  46.     Dim v As Integer
  47.     Dim ratus As Integer
  48.     Dim puluh As Integer
  49.     Dim satu As Integer
  50.     Dim title As String
  51.     Dim perpuluh As Integer
  52.     Dim perribu As Integer
  53.     For k = 0 To 4
  54.         v = arr(k)
  55.         If v = 0 Then
  56.             If k + x = 0 Then
  57.               result(k) = "Nol "
  58.             End If
  59.         ElseIf k * v = 1 Then
  60.             result(k) = "Seribu "
  61.         ElseIf v > 0 Then
  62.             ratus = Int(v / 100)
  63.             puluh = Int((v - 100 * ratus) / 10)
  64.             satu = Int((v - 100 * ratus - 10 * puluh) / 1)
  65.             If ratus = 1 Then
  66.                 result(k) = "Seratus "
  67.             ElseIf ratus > 0 Then
  68.                 result(k) = satuan(ratus) & " Ratus "
  69.             End If
  70.             If (puluh = 1) And (satu = 0) Then
  71.                 result(k) = result(k) & "Sepuluh "
  72.             ElseIf puluh * satu = 1 Then
  73.                 result(k) = result(k) & "Sebelas "
  74.             ElseIf puluh = 1 Then
  75.                 result(k) = result(k) & satuan(satu) & " Belas "
  76.             Else
  77.                 If puluh > 1 Then
  78.                   result(k) = result(k) & satuan(puluh) & " Puluh "
  79.                 End If
  80.                 If satu > 0 Then
  81.                     result(k) = result(k) & satuan(satu) & " "
  82.                 End If
  83.             End If
  84.             If k > 0 Then
  85.                 result(k) = result(k) & ribuan(k) & " "
  86.             End If
  87.         End If
  88.     Next k
  89.     title = result(4) & result(3) & result(2) & result(1) & result(0)
  90.     If sen > 0 Then
  91.         perpuluh = Int(sen / 10)
  92.         perribu = Int((sen - 10 * perpuluh) / 1)
  93.         title = title & "Koma " & satuan(perpuluh) & " " & satuan(perribu)
  94.     End If
  95.     Terbilang = title & "Rupiah"
  96. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement