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

CODING

The document contains code for a userform in Excel VBA. The code defines subroutines for when buttons are clicked to add or exit data. It adds new records to three sheets, validates required fields are entered, and displays the data in listboxes by updating the rowsource properties. Closing the form requires user confirmation before closing.

Uploaded by

faisalchally
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)
26 views4 pages

CODING

The document contains code for a userform in Excel VBA. The code defines subroutines for when buttons are clicked to add or exit data. It adds new records to three sheets, validates required fields are entered, and displays the data in listboxes by updating the rowsource properties. Closing the form requires user confirmation before closing.

Uploaded by

faisalchally
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

Private Sub KELUAR_Click()

Select Case MsgBox("Anda akan keluar dari Aplikasi." _

& vbCrLf & "Apakah anda yakin?" _

, vbYesNo Or vbQuestion Or vbDefaultButton1, "Keluar")

Case vbNo

Exit Sub

Case vbYes

End Select

ThisWorkbook.Save

ThisWorkbook.Close

End Sub

Private Sub TAMBAH_Click()

Dim DB1, DB2, DB3 As Object

Set DB1 = Sheet1.Range("A1000").End(xlUp)

Set DB2 = Sheet2.Range("A1000").End(xlUp)

Set DB3 = Sheet3.Range("A1000").End(xlUp)

If Me.NamaDepan.Value = "" _

Or Me.NamaBelakang.Value = "" _

Or Me.JenisKelamin.Value = "" _

Or Me.alamat.Value = "" _

Or Me.Telpon.Value = "" _

Or Me.Email.Value = "" Then

Call MsgBox("Maaf data input harus lengkap", vbInformation, "Input Data")

Else
'Input Data pada Sheet1

DB1.Offset(1, 0).Value = Me.NamaDepan.Value

DB1.Offset(1, 1).Value = Me.NamaBelakang.Value

DB1.Offset(1, 2).Value = Me.JenisKelamin.Value

DB1.Offset(1, 3).Value = Me.alamat.Value

DB1.Offset(1, 4).Value = Me.Telpon.Value

DB1.Offset(1, 5).Value = Me.Email.Value

'Input Data pada Sheet2

DB2.Offset(1, 0).Value = Me.NamaDepan.Value

DB2.Offset(1, 1).Value = Me.NamaBelakang.Value

DB2.Offset(1, 2).Value = Me.JenisKelamin.Value

DB2.Offset(1, 3).Value = Me.alamat.Value

DB2.Offset(1, 4).Value = Me.Telpon.Value

DB2.Offset(1, 5).Value = Me.Email.Value

'Input Data pada Sheet3

DB3.Offset(1, 0).Value = Me.NamaDepan.Value

DB3.Offset(1, 1).Value = Me.NamaBelakang.Value

DB3.Offset(1, 2).Value = Me.JenisKelamin.Value

DB3.Offset(1, 3).Value = Me.alamat.Value

DB3.Offset(1, 4).Value = Me.Telpon.Value

DB3.Offset(1, 5).Value = Me.Email.Value

'Memunculkan data dari Sheet1

On Error Resume Next

TABEL1.RowSource = "DATA1!A2:f" & Range("F" & Rows.Count).End(xlUp).Row

'Memunculkan data dari Sheet2

TABEL2.RowSource = "DATA2!A2:f" & Range("F" & Rows.Count).End(xlUp).Row


'Memunculkan data dari Sheet3

TABEL3.RowSource = "DATA3!A2:f" & Range("F" & Rows.Count).End(xlUp).Row

Call MsgBox("Transfer data berhasil", vbInformation, "Transfer Data")

Me.NamaDepan.Value = ""

Me.NamaBelakang.Value = ""

Me.JenisKelamin.Value = ""

Me.alamat.Value = ""

Me.Telpon.Value = ""

End If

End Sub

Private Sub UserForm_Initialize()

With JenisKelamin

.AddItem "Laki - Laki"

.AddItem "Perempuan"

End With

'Memunculkan data dari Sheet1

On Error Resume Next

TABEL1.RowSource = "DATA1!A2:f" & Range("F" & Rows.Count).End(xlUp).Row

'Memunculkan data dari Sheet2

TABEL2.RowSource = "DATA2!A2:f" & Range("F" & Rows.Count).End(xlUp).Row

'Memunculkan data dari Sheet3

TABEL3.RowSource = "DATA3!A2:f" & Range("F" & Rows.Count).End(xlUp).Row


End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)

If CloseMode = 0 Then

Cancel = True

End If

End Sub

You might also like