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

Excel VBA Stock Update Form Guide

The document provides a tutorial on using Excel and VBA for stock management, including a form for updating stock and generating reports. It includes code snippets for updating stock data, handling user input, and filtering data based on search criteria. Additionally, it covers initializing user forms and populating combo boxes and list boxes with data from specified ranges.

Uploaded by

iko ericko
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)
7 views3 pages

Excel VBA Stock Update Form Guide

The document provides a tutorial on using Excel and VBA for stock management, including a form for updating stock and generating reports. It includes code snippets for updating stock data, handling user input, and filtering data based on search criteria. Additionally, it covers initializing user forms and populating combo boxes and list boxes with data from specified ranges.

Uploaded by

iko ericko
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

-----------------------------------------------------------------------------------

----------------------
CODING FORM PDATE STOK | EXCEL & VBA TUTORIAL
-----------------------------------------------------------------------------------
----------------------

TOMBOL UPDATE STOK


-----------------------------------------------------------------------------------
----------------------
[Link] = False
Dim UPDATESTOK As Object
Dim DataStok As Object
Set DataStok = [Link]("A1000000").End(xlUp)
Set UPDATESTOK = [Link]("A5:A1000000").Find(what:=[Link],
LookIn:=xlValues)

If [Link] = "" _
Or [Link] = "" _
Or [Link] = "" _
Or [Link] = "" _
Or [Link] = "" _
Or [Link] = "" Then
'Perintah memunculkan pesan jika data inti kosong
Call MsgBox("Maaf, Data input harus lengkap", vbInformation, "Input Data")
'Perintah untuk menyimpan data pada tempat simpan data
Else
[Link](1, 0).Value = Date
[Link](1, 1).Value = [Link]
[Link](1, 2).Value = [Link]
[Link](1, 3).Value = [Link]
[Link](1, 4).Value = [Link]
[Link](1, 5).Value = [Link]
[Link](1, 6).Value = [Link]

[Link](0, 5).Value = [Link]


'Perintah untuk memasukkan data sheet ke dalam listbox
On Error Resume Next
[Link]
[Link] = "stokupdate!A5:G" & Range("G" & [Link]).End(xlUp).Row
Call MsgBox("Data berhasil ditambah", vbInformation, "Input Data")
'Perintah untuk membersihkan form
[Link] = ""
[Link] = ""
[Link] = ""
[Link] = ""
[Link] = ""
[Link] = ""

TAMBAHAN CODING LISTBOX


-----------------------------------------------------------------------------------
-------------
[Link] = [Link]
[Link] = [Link](1)
[Link] = [Link](5)

TAMBAHAN CODING USERFORM INITIALIZE


-----------------------------------------------------------------------------------
-------------
'Perintah Mengisi Combobox Supplier
[Link]
[Link] = "SUPPLIER!B5:B" & Range("B" & [Link]).End(xlUp).Row
'Perintah mengisi tabel Updat Stok
[Link]
[Link] = "stokupdate!A5:G" & Range("G" &
[Link]).End(xlUp).Row
[Link]
[Link] = False

CODING FORM LAPORAN


-----------------------------------------------------------------------------------
------------
Private Sub CARI_Click()
On Error GoTo salah
If [Link] = "" Then
Call MsgBox("Isi data pencarian terlebih dahulu", vbInformation, "Cari data")
Else
Set Cari_Data = Sheet5
Cari_Data.Range("M4").Value = [Link]
Cari_Data.Range("M5").Value = [Link]

Cari_Data.Range("A4").[Link] Action:=xlFilterCopy,
CriteriaRange:= _
[Link]("M4:N5"), CopyToRange:=[Link]("P4:Z4"), Unique:=False
On Error Resume Next
[Link] = False
[Link]
[Link] = "LAPORANTRANSAKSI!P5:Z" & Range("Z" &
[Link]).End(xlUp).Row
[Link]
[Link] = [Link]([Link]("V5:V1000000"))
[Link] = [Link]([Link]("W5:W1000000"))
[Link] = [Link]([Link]("Y5:Y1000000"))
[Link] = (IIf([Link] = "", 0,
[Link])) - (IIf([Link] = "", 0, [Link]))
[Link] = Format([Link], "Rp #,###")
[Link] = Format([Link], "Rp #,###")
[Link] = Format([Link], "Rp #,###")

End If
Exit Sub
salah:
Call MsgBox("Maaf Data tidak ditemukan", vbInformation, "Cari Data")

End Sub

Private Sub MonthView1_DateClick(ByVal DateClicked As Date)


[Link] = [Link]
[Link]("N5").Value = [Link]
[Link]("N5").Value = Format([Link]("N5").Value, "MM/dd/yyyy")

End Sub

Private Sub RESET_Click()


[Link] = ""
[Link] = ""
[Link] = ""
[Link]("M5").Value = ""
[Link]("N5").Value = ""
On Error Resume Next
[Link] = False
[Link]
[Link] = "LAPORANTRANSAKSI!A5:K" & Range("K" &
[Link]).End(xlUp).Row
[Link]
[Link] = ""
[Link] = ""
[Link] = ""
[Link] = ""
End Sub
Private Sub UserForm_Initialize()
On Error Resume Next
[Link] = False
[Link]
[Link] = "LAPORANTRANSAKSI!A5:K" & Range("K" &
[Link]).End(xlUp).Row
[Link]
With BERDASARKAN
.AddItem "Kode Transaksi"
.AddItem "Nama Customer"
.AddItem "Id Barang"
.AddItem "Nama Barang"
End With
[Link]("M5").Value = ""
[Link]("N5").Value = ""

End Sub

Common questions

Powered by AI

The 'RESET_Click' subroutine clears the search criteria fields (BERDASARKAN, KATAKUNCI, TANGGAL) and resets corresponding cells (M5, N5) on Sheet5. It prevents screen updates during operation to optimize performance, updates the ListBox to show all transaction records (from 'A5:K'), and clears the summary labels (HARGASATUAN, DISKON, TOTALHARGA, JUMLAHBARANG) to ensure the form is ready for new input or search operations .

The 'On Error Resume Next' statement is used to allow the code to continue running even after an error occurs, effectively suppressing runtime errors. This is useful in scenarios where the presence of certain errors is acceptable (e.g., initially empty ranges). However, it can lead to unnoticed errors if not managed carefully, as it bypasses traditional error handling methods that would alert the programmer to potential issues in the code .

'WorksheetFunction.Sum' is used to calculate the sum of specific ranges, such as the total quantity, unit price, and discount. The code applies it to compute summary information (JUMLAHBARANG, HARGASATUAN, DISKON, TOTALHARGA) which are displayed on the form. This ensures efficient aggregation of data retrieved from Sheet5, allowing users to view comprehensive summary metrics directly within the form .

The 'CARI_Click' subroutine first checks if the search criteria (BERDASARKAN and KATAKUNCI) are provided. If not, it displays a message prompting the user to input search data. It then records these criteria in specific cells (M4 and M5) on Sheet5. An Advanced Filter operation is executed using these criteria, filtering data from Sheet5's column 'A4' to be copied to columns 'P4:Z4'. The results are shown in a ListBox, while summary calculations (JUMLAHBARANG, HARGASATUAN, DISKON, TOTALHARGA) are performed and formatted accordingly .

The 'MonthView1_DateClick' event handler sets the TANGGAL control's value to the selected date from MonthView1. It then updates the N5 cell on Sheet5 with this date, formatting it as 'MM/dd/yyyy', ensuring consistency in date representation within the application .

During userform initialization, the code sets the list of possible search criteria options (e.g., 'Kode Transaksi', 'Nama Customer') in the BERDASARKAN combobox. It clears previous values in specific cells (M5, N5) on Sheet5 and sets the ListBox to display the relevant transaction data range ('A5:K'). This setup ensures the userform is prepped with necessary configurations and ready for immediate use, enhancing user experience by providing default search parameters .

The code employs several strategies to handle user input errors and maintain robustness: It validates essential input fields, showing an error message if any are empty, and uses 'On Error Resume Next' to prevent the code from crashing due to unexpected conditions. These measures ensure that data operations only proceed when input is correct, thereby maintaining data integrity and application stability, while careful range management prevents common errors related to data entry or manipulation .

After updating the stock information, the code sets the RowSource property of the ListBox (TABELUPDATE) to the range containing the updated data ('stokupdate!A5:G' to the last row of column G) on Sheet9. This dynamically updates the content displayed in the ListBox with the most recent data entries .

The VBA code checks if any key fields (KODE1, NAMA1, SUPPLIER, STOKAWAL, TAMBAHSTOK, TOTALSTOK) are empty before proceeding. If any of these fields are empty, a message box (MsgBox) is triggered to inform the user that complete data is required, preventing further processing until all fields are filled .

The purpose of using 'Application.ScreenUpdating = False' is to improve the efficiency of the macro by preventing Excel from updating the screen until the code execution is complete. This reduces flickering and speeds up the process, as the screen is not continuously refreshed during code execution .

You might also like