0% found this document useful (0 votes)
44 views4 pages

Coding Form Penghitungan

The document contains VBA code for a userform in Excel that is used for managing product inventory and transactions. The code handles clearing fields, formatting currency fields, calculating totals when fields change, validating required fields, saving transaction data to a sheet, and initializing drop down lists when the form opens.

Uploaded by

ferry kusnadi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views4 pages

Coding Form Penghitungan

The document contains VBA code for a userform in Excel that is used for managing product inventory and transactions. The code handles clearing fields, formatting currency fields, calculating totals when fields change, validating required fields, saving transaction data to a sheet, and initializing drop down lists when the form opens.

Uploaded by

ferry kusnadi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

CODING FORM PENGHITUNGAN

Private Sub BERSIHKAN_Click()

Me.KodeBArang.Value = ""

Me.NamaBArang.Value = ""

Me.Supplier.Value = ""

Me.Satuan.Value = ""

Me.HArgaBarang.Value = ""

Me.Jumlah.Value = ""

Me.Diskon.Value = ""

Me.TotalHarga.Value = ""

Me.TotalBayar.Value = ""

End Sub

Private Sub Diskon_Change()

Me.Diskon.Value = Format(Me.Diskon.Value, "Rp #,###")

End Sub

Private Sub HArgaBarang_Change()

Me.HArgaBarang.Value = Format(Me.HArgaBarang.Value, "Rp #,###")

End Sub

Private Sub HITUNG_Click()

If Me.Jumlah.Value = "" Then

Call MsgBox("Harap isi jumlah pembelian", vbInformation, "Jumlah Beli")

Else

Me.TotalHarga.Value = (IIf(Me.HArgaBarang.Value = "", 0, Me.HArgaBarang.Value)) *


(IIf(Me.Jumlah.Value = "", 0, Me.Jumlah.Value))
Me.TotalBayar.Value = (IIf(Me.TotalHarga.Value = "", 0, Me.TotalHarga.Value)) - (IIf(Me.Diskon.Value
= "", 0, Me.Diskon.Value))

Me.LABELTOTAL.Caption = (IIf(Me.TotalHarga.Value = "", 0, Me.TotalHarga.Value)) -


(IIf(Me.Diskon.Value = "", 0, Me.Diskon.Value))

Me.LABELTOTAL.Caption = Format(Me.LABELTOTAL.Caption, "Rp #,###")

End If

End Sub

Private Sub KodeBArang_Change()

Set DataBarang = Sheet1.Range("A3:A10000").Find(What:=Me.KodeBArang.Value, LookIn:=xlValues)

Me.NamaBArang.Value = DataBarang.Offset(0, 1).Value

Me.Supplier.Value = DataBarang.Offset(0, 2).Value

Me.Satuan.Value = DataBarang.Offset(0, 3).Value

Me.HArgaBarang.Value = DataBarang.Offset(0, 4).Value

End Sub

Private Sub TAMBAHDATA_Click()

Dim DataBeli As Object

Set DataBeli = Sheet2.Range("A10000").End(xlUp)

If Me.KodeBArang.Value = "" _

Or Me.Jumlah.Value = "" Then

Call MsgBox("Transaksi masih kosong, harap masukkan transaksi", vbInformation, "Transaksi")

Else

DataBeli.Offset(1, 0).Value = Me.KodeBArang.Value

DataBeli.Offset(1, 1).Value = Me.NamaBArang.Value

DataBeli.Offset(1, 2).Value = Me.Supplier.Value

DataBeli.Offset(1, 3).Value = Me.Satuan.Value

DataBeli.Offset(1, 4).Value = Me.HArgaBarang.Value

DataBeli.Offset(1, 5).Value = Me.Jumlah.Value

DataBeli.Offset(1, 6).Value = Me.Diskon.Value


DataBeli.Offset(1, 7).Value = Me.TotalHarga.Value

DataBeli.Offset(1, 8).Value = Me.TotalBayar.Value

Call MsgBox("Data transaksi berhasil disimpan", vbInformation, "Transaksi")

Me.TABELDATA.RowSource = Sheet2.Range("Transaksi").Address(External:=True)

Me.KodeBArang.Value = ""

Me.NamaBArang.Value = ""

Me.Supplier.Value = ""

Me.Satuan.Value = ""

Me.HArgaBarang.Value = ""

Me.Jumlah.Value = ""

Me.Diskon.Value = ""

Me.TotalHarga.Value = ""

Me.TotalBayar.Value = ""

Me.LABELTOTAL.Caption = ""

End If

End Sub

Private Sub TotalBayar_Change()

Me.TotalBayar.Value = Format(Me.TotalBayar.Value, "Rp #,###")

End Sub

Private Sub TotalHarga_Change()

Me.TotalHarga.Value = Format(Me.TotalHarga.Value, "Rp #,###")

End Sub

Private Sub tutup_Click()

Unload Me

End Sub
Private Sub UserForm_Initialize()

On Error Resume Next

Me.KodeBArang.RowSource = Sheet1.Range("Kode_Barang").Address(External:=True)

Me.TABELDATA.RowSource = Sheet2.Range("Transaksi").Address(External:=True)

End Sub

You might also like