Video : Input Data menggunakan User Form
Tutorial Level 6
Kode program 1 pada module:
Sub PanggilFormInput()UserForm1.ShowEnd Sub
Kode program pada Tombol CANCEL:
Private Sub CommandButton1_Click()Unload MeEnd Sub
Kode program pada Tombol SAVE:
Private Sub CommandButton2_Click()SimpanEnd Sub
Kode Program 2 pada module:
Sub Simpan()Dim LokasiDB As StringDim Nomr As LongDim Nama As StringDim Alamat As StringDim Keterangan As StringDim WB1 As WorkbookDim WB2 As WorkbookDim WS1_1 As WorksheetDim WS2_1 As WorksheetDim BarAkhr As Long
Set WB1 = ThisWorkbookSet WS1_1 = WB1.Worksheets("Form")
With WS1_1 LokasiDB = .Cells(6, 7).Value
Nomr = UserForm1.TextBox1.Value Nama = UserForm1.TextBox2.Value Alamat = UserForm1.TextBox3.Value Keterangan = UserForm1.TextBox4.Value
If IsEmpty(Nomr) Or Nama = "" Or Alamat = "" Then MsgBox "Lengkapi input form!" Exit Sub End IfEnd With
Set WB2 = Workbooks.Open(LokasiDB)Set WS2_1 = WB2.Worksheets("Database")
With WS2_1 BarAkhr = .Cells(.Cells.Rows.Count, 1).End(xlUp).Row .Cells(BarAkhr + 1, 1).Value = Nomr .Cells(BarAkhr + 1, 2).Value = Nama .Cells(BarAkhr + 1, 3).Value = Alamat .Cells(BarAkhr + 1, 4).Value = KeteranganEnd With
Application.DisplayAlerts = FalseWB2.Close SaveChanges:=TrueApplication.DisplayAlerts = True
MsgBox "Data telah disimpan.."
End Sub
Halo, Pembaca Klinik Excel.. Bantu kami tetap online yuk..
ula yang serius pengen belajar MACRO VBA Excel, silahkan baca buku berikut: