0% found this document useful (0 votes)
9 views3 pages

Form Barang

The document contains VBA code for a user form that manages inventory data, allowing users to add, delete, reset, and update item information. It includes error handling and user prompts for confirmation during deletion and ensures all fields are filled before adding new data. The form updates a data source in an Excel sheet and resets input fields after operations.

Uploaded by

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

Form Barang

The document contains VBA code for a user form that manages inventory data, allowing users to add, delete, reset, and update item information. It includes error handling and user prompts for confirmation during deletion and ensures all fields are filled before adding new data. The form updates a data source in an Excel sheet and resets input fields after operations.

Uploaded by

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

Private Sub DELETE_Click()

On Error Resume Next


Application.ScreenUpdating = False
If Me.KODE_BARANG.Value = "" Then
Call MsgBox("Pilih data pada tabel data", vbInformation, "Hapus Data")
Else
Select Case MsgBox("Anda akan menghapus data" _
& vbCrLf & "Apakah anda yakin?" _
, vbYesNo Or vbQuestion Or vbDefaultButton1, "Hapus data")
Case vbNo
Exit Sub
Case vbYes
End Select
Set Hapusdata = Sheet1.Range("A5:A40000").Find(What:=Me.KODE_BARANG.Value,
LookIn:=xlValues)
Hapusdata.Offset(0, 0).ClearContents
Hapusdata.Offset(0, 1).ClearContents
Hapusdata.Offset(0, 2).ClearContents
Hapusdata.Offset(0, 3).ClearContents
Hapusdata.Offset(0, 4).ClearContents
Hapusdata.Offset(0, 5).ClearContents
Hapusdata.Offset(0, 6).ClearContents

Call MsgBox("Data berhasil dihapus", vbInformation, "Hapus Data")


Me.KODE_BARANG.Text = ""
Me.NAMA_BARANG.Text = ""
Me.STOK.Text = ""
Me.SATUAN.Text = ""
Me.HARGA_BELI.Text = ""
Me.HARGA_JUAL.Text = ""
Me.LOKASI.Text = ""

End If
Call UrutDataHapus
Me.TAMBAH.Enabled = True
End Sub

Private Sub RESET_Click()


Me.KODE_BARANG.Text = ""
Me.NAMA_BARANG.Text = ""
Me.STOK.Text = ""
Me.SATUAN.Text = ""
Me.HARGA_BELI.Text = ""
Me.HARGA_JUAL.Text = ""
Me.LOKASI.Text = ""
Me.TAMBAH.Enabled = True
End Sub

Private Sub TAMBAH_Click()


Application.ScreenUpdating = False
Dim DataBarang As Object
Set DataBarang = Sheet1.Range("A10000").End(xlUp)
If Me.KODE_BARANG.Value = "" _
Or Me.NAMA_BARANG.Value = "" _
Or Me.STOK.Value = "" _
Or Me.SATUAN.Value = "" _
Or Me.HARGA_BELI.Value = "" _
Or Me.HARGA_JUAL.Value = "" _
Or Me.LOKASI.Value = "" Then
Call MsgBox("Maaf, Data input harus lengkap", vbInformation, "Input Data")
Else
DataBarang.Offset(1, 0).Value = Me.KODE_BARANG.Value
DataBarang.Offset(1, 1).Value = Me.NAMA_BARANG.Value
DataBarang.Offset(1, 2).Value = Me.STOK.Value
DataBarang.Offset(1, 3).Value = Me.SATUAN.Value
DataBarang.Offset(1, 4).Value = Me.HARGA_BELI.Value
DataBarang.Offset(1, 5).Value = Me.HARGA_JUAL.Value
DataBarang.Offset(1, 6).Value = Me.LOKASI.Value
On Error Resume Next
Sheet1.Select
DATA_BARANG.RowSource = "Data_Barang!A5:G" & Range("G" & Rows.Count).End(xlUp).Row
Call MsgBox("Data berhasil ditambah", vbInformation, "Input Data")
Me.KODE_BARANG.Text = ""
Me.NAMA_BARANG.Text = ""
Me.STOK.Text = ""
Me.SATUAN.Text = ""
Me.HARGA_BELI.Text = ""
Me.HARGA_JUAL.Text = ""
Me.LOKASI.Text = ""
End If
Sheet1.Select
End Sub

Private Sub DATA_BARANG_DblClick(ByVal Cancel As MSForms.ReturnBoolean)


Application.ScreenUpdating = False
On Error GoTo Salah
Dim CellAktif, SUMBERUBAH As Long
Me.KODE_BARANG.Value = Me.DATA_BARANG.Value
Me.NAMA_BARANG.Value = Me.DATA_BARANG.Column(1)
Me.STOK.Value = Me.DATA_BARANG.Column(2)
Me.SATUAN.Value = Me.DATA_BARANG.Column(3)
Me.HARGA_BELI.Value = Me.DATA_BARANG.Column(4)
Me.HARGA_JUAL = Me.DATA_BARANG.Column(5)
Me.LOKASI.Value = Me.DATA_BARANG.Column(6)
Me.TAMBAH.Enabled = False
Sheet1.Select
Salah:
End Sub

Private Sub UBAH_Click()


Application.ScreenUpdating = False
Dim Baris, SUMBERUBAH As String
If Me.KODE_BARANG.Text = "" Then
Call MsgBox("Pilih data terlebih dahulu", vbInformation, "Pilih Data")
Else
Sheet1.Select
SUMBERUBAH = Sheets("Data_Barang").Cells(Rows.Count, "A").End(xlUp).Row
Sheets("Data_Barang").Range("A5:A" & SUMBERUBAH).Find(What:=DATA_BARANG.Text,
LookIn:=xlValues, Lookat:=xlWhole).Activate
Baris = ActiveCell.Row
Cells(Baris, 1) = Me.KODE_BARANG.Text
Cells(Baris, 2) = Me.NAMA_BARANG.Text
Cells(Baris, 3) = Me.STOK.Text
Cells(Baris, 4) = Me.SATUAN.Text
Cells(Baris, 5) = Me.HARGA_BELI.Text
Cells(Baris, 6) = Me.HARGA_JUAL.Text
Cells(Baris, 7) = Me.LOKASI.Text
Call MsgBox("Data berhasil diubah", vbInformation, "Ubah Data")
Me.KODE_BARANG.Text = ""
Me.NAMA_BARANG.Text = ""
Me.STOK.Text = ""
Me.SATUAN.Text = ""
Me.HARGA_BELI.Text = ""
Me.HARGA_JUAL.Text = ""
Me.LOKASI.Text = ""

End If
Me.TAMBAH.Enabled = True
Sheet1.Select
End Sub

Private Sub UserForm_Activate()


Sheet1.Select
Me.DATA_BARANG.RowSource = "Data_barang!A5:G" & Range("G" &
Rows.Count).End(xlUp).Row
Sheet1.Select
End Sub

You might also like