CARA MEMBUAT ADD IN TERBILANG UNTUK MICROSOFT EXCEL 2007
Bagaimana membuat membuat Add In terbilang (menterjemahkan angka menjadi kata-kata ) pada Microsoft Excel 2007. Bagi anda yang sering membuat tanda terima pembayaran tentunya sering kali anda harus menterjemahkan angka-angka menjadi kata-kata, misal Rp. 1000,- diterjemahkan menjadi "Seribu Rupiah", tentu akan sangat melelahkan jika hal ini harus dikerjakan secara manual, dimana anda harus mengeja setiap angka pada transaksi anda untuk kemudian anda ketik. Tujuan Add In ini saya berharap akan bisa membantu mempermudah pekerjaan dalam membuat tanda terima dan mempersingkat proses.
Langkah-langkahnya sebagai berikut :
1. Copy paste kode dibawah ini pada notepad ("Terbilang dengan akhiran rupiah" atau "Terbilangan tanpa akhiran rupiah")
2. Lalu Save As dengan akhiran "terbilang.xlam" dan taruh terserah anda, contoh c:/My Documents
3. Kemuadian buka excel 2007
4. Excel Option
Langkah-langkahnya sebagai berikut :
1. Copy paste kode dibawah ini pada notepad ("Terbilang dengan akhiran rupiah" atau "Terbilangan tanpa akhiran rupiah")
2. Lalu Save As dengan akhiran "terbilang.xlam" dan taruh terserah anda, contoh c:/My Documents
3. Kemuadian buka excel 2007
4. Excel Option
Sekarang kita check apakah fungsi tersebut berfungsi. Untuk memakainya anda perlu mengetahui formulanya. Misal angka yang hendak anda buatkan terbilangnya ada di cell "A1", maka formulanya adalah sebagai berikut :
=terbilang(A1,4,"Rupiah.")
Attribute VB_Name = "Module1"
Option Explicit
Function Terbilang(ByVal MyNumber)
Dim Rupiah, Sen, Temp
Dim Des, Desimal, Count, Tmp
Dim IsNeg
ReDim Place(9) As String
Place(2) = "RIBU "
Place(3) = "JUTA "
Place(4) = "MILYAR "
Place(5) = "TRILYUN "
'Ubah angka menjadi string
MyNumber = Round(MyNumber, 2)
MyNumber = Trim(Str(MyNumber))
'Cek bilangan negatif
If Mid(MyNumber, 1, 1) = "-" Then
MyNumber = Right(MyNumber, Len(MyNumber) - 1)
IsNeg = True
End If
'Posisi desimal, 0 jika bil. bulat
Desimal = InStr(MyNumber, ".")
'Pembulatan sen, dua angka di belakang koma
Des = Mid(MyNumber, Desimal + 2)
If Desimal > 0 Then
Tmp = Left(Mid(MyNumber, Desimal + 1) & "00", 2)
If Left(Tmp, 1) = "0" Then
Tmp = Mid(Tmp, 2)
Sen = Satuan(Tmp)
Else
Sen = Puluhan(Tmp)
End If
MyNumber = Trim(Left(MyNumber, Desimal - 1))
End If
Count = 1
Do While MyNumber <> ""
Temp = Ratusan(Right(MyNumber, 3), Count)
If Temp <> "" Then Rupiah = Temp & Place(Count) & Rupiah
If Len(MyNumber) > 3 Then
MyNumber = Left(MyNumber, Len(MyNumber) - 3)
Else
MyNumber = ""
End If
Count = Count + 1
Loop
Select Case Rupiah
Case ""
Rupiah = "NOL RUPIAH"
Case Else
Rupiah = Rupiah & "RUPIAH"
End Select
Select Case Sen
Case ""
Sen = ""
Case Else
Sen = " DAN " & Sen & "SEN"
End Select
If IsNeg = True Then
Terbilang = "MINUS " & Rupiah & Sen
Else
Terbilang = Rupiah & Sen
End If
End Function
' Mengubah angka 100-999 menjadi teks *
Function Ratusan(ByVal MyNumber, Count)
Dim Result As String
Dim Tmp
If Val(MyNumber) = 0 Then Exit Function
MyNumber = Right("000" & MyNumber, 3)
'Mengubah seribu
If MyNumber = "001" And Count = 2 Then
Ratusan = "SE"
Exit Function
End If
'Mengubah ratusan
If Mid(MyNumber, 1, 1) <> "0" Then
If Mid(MyNumber, 1, 1) = "1" Then
Result = "SERATUS "
Else
Result = Satuan(Mid(MyNumber, 1, 1)) & "RATUS "
End If
End If
'Mengubah puluhan dan satuan
If Mid(MyNumber, 2, 1) <> "0" Then
Result = Result & Puluhan(Mid(MyNumber, 2))
Else
Result = Result & Satuan(Mid(MyNumber, 3))
End If
Ratusan = Result
End Function
'*******************
' Mengubah puluhan *
Function Puluhan(TeksPuluhan)
Dim Result As String
Result = ""
' nilai antara 10-19
If Val(Left(TeksPuluhan, 1)) = 1 Then
Select Case Val(TeksPuluhan)
Case 10: Result = "SEPULUH "
Case 11: Result = "SEBELAS "
Case Else
Result = Satuan(Mid(TeksPuluhan, 2)) & "BELAS "
End Select
' nilai antara 20-99
Else
Result = Satuan(Mid(TeksPuluhan, 1, 1)) _
& "PULUH "
Result = Result & Satuan(Right(TeksPuluhan, 1))
'satuan
End If
Puluhan = Result
End Function
'********************************
' Mengubah satuan menjadi teks. *
Function Satuan(Digit)
Select Case Val(Digit)
Case 1: Satuan = "SATU "
Case 2: Satuan = "DUA "
Case 3: Satuan = "TIGA "
Case 4: Satuan = "EMPAT "
Case 5: Satuan = "LIMA "
Case 6: Satuan = "ENAM "
Case 7: Satuan = "TUJUH "
Case 8: Satuan = "DELAPAN "
Case 9: Satuan = "SEMBILAN "
Case Else: Satuan = ""
End Select
End Function
Option Explicit
Function Terbilang(ByVal MyNumber)
Dim Rupiah, Sen, Temp
Dim Des, Desimal, Count, Tmp
Dim IsNeg
ReDim Place(9) As String
Place(2) = "RIBU "
Place(3) = "JUTA "
Place(4) = "MILYAR "
Place(5) = "TRILYUN "
'Ubah angka menjadi string
MyNumber = Round(MyNumber, 2)
MyNumber = Trim(Str(MyNumber))
'Cek bilangan negatif
If Mid(MyNumber, 1, 1) = "-" Then
MyNumber = Right(MyNumber, Len(MyNumber) - 1)
IsNeg = True
End If
'Posisi desimal, 0 jika bil. bulat
Desimal = InStr(MyNumber, ".")
'Pembulatan sen, dua angka di belakang koma
Des = Mid(MyNumber, Desimal + 2)
If Desimal > 0 Then
Tmp = Left(Mid(MyNumber, Desimal + 1) & "00", 2)
If Left(Tmp, 1) = "0" Then
Tmp = Mid(Tmp, 2)
Sen = Satuan(Tmp)
Else
Sen = Puluhan(Tmp)
End If
MyNumber = Trim(Left(MyNumber, Desimal - 1))
End If
Count = 1
Do While MyNumber <> ""
Temp = Ratusan(Right(MyNumber, 3), Count)
If Temp <> "" Then Rupiah = Temp & Place(Count) & Rupiah
If Len(MyNumber) > 3 Then
MyNumber = Left(MyNumber, Len(MyNumber) - 3)
Else
MyNumber = ""
End If
Count = Count + 1
Loop
Select Case Rupiah
Case ""
Rupiah = "NOL RUPIAH"
Case Else
Rupiah = Rupiah & "RUPIAH"
End Select
Select Case Sen
Case ""
Sen = ""
Case Else
Sen = " DAN " & Sen & "SEN"
End Select
If IsNeg = True Then
Terbilang = "MINUS " & Rupiah & Sen
Else
Terbilang = Rupiah & Sen
End If
End Function
' Mengubah angka 100-999 menjadi teks *
Function Ratusan(ByVal MyNumber, Count)
Dim Result As String
Dim Tmp
If Val(MyNumber) = 0 Then Exit Function
MyNumber = Right("000" & MyNumber, 3)
'Mengubah seribu
If MyNumber = "001" And Count = 2 Then
Ratusan = "SE"
Exit Function
End If
'Mengubah ratusan
If Mid(MyNumber, 1, 1) <> "0" Then
If Mid(MyNumber, 1, 1) = "1" Then
Result = "SERATUS "
Else
Result = Satuan(Mid(MyNumber, 1, 1)) & "RATUS "
End If
End If
'Mengubah puluhan dan satuan
If Mid(MyNumber, 2, 1) <> "0" Then
Result = Result & Puluhan(Mid(MyNumber, 2))
Else
Result = Result & Satuan(Mid(MyNumber, 3))
End If
Ratusan = Result
End Function
'*******************
' Mengubah puluhan *
Function Puluhan(TeksPuluhan)
Dim Result As String
Result = ""
' nilai antara 10-19
If Val(Left(TeksPuluhan, 1)) = 1 Then
Select Case Val(TeksPuluhan)
Case 10: Result = "SEPULUH "
Case 11: Result = "SEBELAS "
Case Else
Result = Satuan(Mid(TeksPuluhan, 2)) & "BELAS "
End Select
' nilai antara 20-99
Else
Result = Satuan(Mid(TeksPuluhan, 1, 1)) _
& "PULUH "
Result = Result & Satuan(Right(TeksPuluhan, 1))
'satuan
End If
Puluhan = Result
End Function
'********************************
' Mengubah satuan menjadi teks. *
Function Satuan(Digit)
Select Case Val(Digit)
Case 1: Satuan = "SATU "
Case 2: Satuan = "DUA "
Case 3: Satuan = "TIGA "
Case 4: Satuan = "EMPAT "
Case 5: Satuan = "LIMA "
Case 6: Satuan = "ENAM "
Case 7: Satuan = "TUJUH "
Case 8: Satuan = "DELAPAN "
Case 9: Satuan = "SEMBILAN "
Case Else: Satuan = ""
End Select
End Function
Kode terbilang tanpa akhiran rupiah :
Function Terbilang(ByVal MyNumber)
Dim Rupiah, Sen, Temp
Dim Des, Desimal, Count, Tmp
Dim IsNeg
ReDim Place(9) As String
Place(2) = "ribu "
Place(3) = "juta "
Place(4) = "milyar "
Place(5) = "trilyun "
'Ubah angka menjadi string
MyNumber = Round(MyNumber, 2)
MyNumber = Trim(Str(MyNumber))
'Cek bilangan negatif
If Mid(MyNumber, 1, 1) = "-" Then
MyNumber = Right(MyNumber, Len(MyNumber) - 1)
IsNeg = True
End If
'Posisi desimal, 0 jika bil. bulat
Desimal = InStr(MyNumber, ".")
'Pembulatan sen, dua angka di belakang koma
Des = Mid(MyNumber, Desimal + 2)
If Desimal > 0 Then
Tmp = Left(Mid(MyNumber, Desimal + 1) & "00", 2)
If Left(Tmp, 1) = "0" Then
Tmp = Mid(Tmp, 2)
Sen = Satuan(Tmp)
Else
Sen = Puluhan(Tmp)
End If
MyNumber = Trim(Left(MyNumber, Desimal - 1))
End If
Count = 1
Do While MyNumber <> ""
Temp = Ratusan(Right(MyNumber, 3), Count)
If Temp <> "" Then Rupiah = Temp & Place(Count) & Rupiah
If Len(MyNumber) > 3 Then
MyNumber = Left(MyNumber, Len(MyNumber) - 3)
Else
MyNumber = ""
End If
Count = Count + 1
Loop
Select Case Rupiah
Case ""
Rupiah = "nol rupiah"
Case Else
Rupiah = Rupiah & "rupiah"
End Select
Select Case Sen
Case ""
Sen = ""
Case Else
Sen = " dan " & Sen & "sen"
End Select
If IsNeg = True Then
Terbilang = "minus " & Rupiah & Sen
Else
Terbilang = Rupiah & Sen
End If
End Function
'**************************************
' Mengubah angka 100-999 menjadi teks *
'**************************************
Function Ratusan(ByVal MyNumber, Count)
Dim Result As String
Dim Tmp
If Val(MyNumber) = 0 Then Exit Function
MyNumber = Right("000" & MyNumber, 3)
'Mengubah seribu
If MyNumber = "001" And Count = 2 Then
Ratusan = "se"
Exit Function
End If
'Mengubah ratusan
If Mid(MyNumber, 1, 1) <> "0" Then
If Mid(MyNumber, 1, 1) = "1" Then
Result = "seratus "
Else
Result = Satuan(Mid(MyNumber, 1, 1)) & "ratus "
End If
End If
'Mengubah puluhan dan satuan
If Mid(MyNumber, 2, 1) <> "0" Then
Result = Result & Puluhan(Mid(MyNumber, 2))
Else
Result = Result & Satuan(Mid(MyNumber, 3))
End If
Ratusan = Result
End Function
'*******************
' Mengubah puluhan *
'*******************
Function Puluhan(TeksPuluhan)
Dim Result As String
Result = ""
' nilai antara 10-19
If Val(Left(TeksPuluhan, 1)) = 1 Then
Select Case Val(TeksPuluhan)
Case 10: Result = "sepuluh "
Case 11: Result = "sebelas "
Case Else
Result = Satuan(Mid(TeksPuluhan, 2)) & "belas "
End Select
' nilai antara 20-99
Else
Result = Satuan(Mid(TeksPuluhan, 1, 1)) _
& "puluh "
Result = Result & Satuan(Right(TeksPuluhan, 1))
'satuan
End If
Puluhan = Result
End Function
'********************************
' Mengubah satuan menjadi teks. *
'********************************
Function Satuan(Digit)
Select Case Val(Digit)
Case 1: Satuan = "satu "
Case 2: Satuan = "dua "
Case 3: Satuan = "tiga "
Case 4: Satuan = "empat "
Case 5: Satuan = "lima "
Case 6: Satuan = "enam "
Case 7: Satuan = "tujuh "
Case 8: Satuan = "delapan "
Case 9: Satuan = "sembilan "
Case Else: Satuan = ""
End Select
End Function
Dim Rupiah, Sen, Temp
Dim Des, Desimal, Count, Tmp
Dim IsNeg
ReDim Place(9) As String
Place(2) = "ribu "
Place(3) = "juta "
Place(4) = "milyar "
Place(5) = "trilyun "
'Ubah angka menjadi string
MyNumber = Round(MyNumber, 2)
MyNumber = Trim(Str(MyNumber))
'Cek bilangan negatif
If Mid(MyNumber, 1, 1) = "-" Then
MyNumber = Right(MyNumber, Len(MyNumber) - 1)
IsNeg = True
End If
'Posisi desimal, 0 jika bil. bulat
Desimal = InStr(MyNumber, ".")
'Pembulatan sen, dua angka di belakang koma
Des = Mid(MyNumber, Desimal + 2)
If Desimal > 0 Then
Tmp = Left(Mid(MyNumber, Desimal + 1) & "00", 2)
If Left(Tmp, 1) = "0" Then
Tmp = Mid(Tmp, 2)
Sen = Satuan(Tmp)
Else
Sen = Puluhan(Tmp)
End If
MyNumber = Trim(Left(MyNumber, Desimal - 1))
End If
Count = 1
Do While MyNumber <> ""
Temp = Ratusan(Right(MyNumber, 3), Count)
If Temp <> "" Then Rupiah = Temp & Place(Count) & Rupiah
If Len(MyNumber) > 3 Then
MyNumber = Left(MyNumber, Len(MyNumber) - 3)
Else
MyNumber = ""
End If
Count = Count + 1
Loop
Select Case Rupiah
Case ""
Rupiah = "nol rupiah"
Case Else
Rupiah = Rupiah & "rupiah"
End Select
Select Case Sen
Case ""
Sen = ""
Case Else
Sen = " dan " & Sen & "sen"
End Select
If IsNeg = True Then
Terbilang = "minus " & Rupiah & Sen
Else
Terbilang = Rupiah & Sen
End If
End Function
'**************************************
' Mengubah angka 100-999 menjadi teks *
'**************************************
Function Ratusan(ByVal MyNumber, Count)
Dim Result As String
Dim Tmp
If Val(MyNumber) = 0 Then Exit Function
MyNumber = Right("000" & MyNumber, 3)
'Mengubah seribu
If MyNumber = "001" And Count = 2 Then
Ratusan = "se"
Exit Function
End If
'Mengubah ratusan
If Mid(MyNumber, 1, 1) <> "0" Then
If Mid(MyNumber, 1, 1) = "1" Then
Result = "seratus "
Else
Result = Satuan(Mid(MyNumber, 1, 1)) & "ratus "
End If
End If
'Mengubah puluhan dan satuan
If Mid(MyNumber, 2, 1) <> "0" Then
Result = Result & Puluhan(Mid(MyNumber, 2))
Else
Result = Result & Satuan(Mid(MyNumber, 3))
End If
Ratusan = Result
End Function
'*******************
' Mengubah puluhan *
'*******************
Function Puluhan(TeksPuluhan)
Dim Result As String
Result = ""
' nilai antara 10-19
If Val(Left(TeksPuluhan, 1)) = 1 Then
Select Case Val(TeksPuluhan)
Case 10: Result = "sepuluh "
Case 11: Result = "sebelas "
Case Else
Result = Satuan(Mid(TeksPuluhan, 2)) & "belas "
End Select
' nilai antara 20-99
Else
Result = Satuan(Mid(TeksPuluhan, 1, 1)) _
& "puluh "
Result = Result & Satuan(Right(TeksPuluhan, 1))
'satuan
End If
Puluhan = Result
End Function
'********************************
' Mengubah satuan menjadi teks. *
'********************************
Function Satuan(Digit)
Select Case Val(Digit)
Case 1: Satuan = "satu "
Case 2: Satuan = "dua "
Case 3: Satuan = "tiga "
Case 4: Satuan = "empat "
Case 5: Satuan = "lima "
Case 6: Satuan = "enam "
Case 7: Satuan = "tujuh "
Case 8: Satuan = "delapan "
Case 9: Satuan = "sembilan "
Case Else: Satuan = ""
End Select
End Function
Tidak ada komentar:
Posting Komentar