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

Coding CRUD

The document contains VBA code for user forms related to education and job positions in Excel. It includes functionalities for adding, deleting, and displaying data from a worksheet, with error handling and user prompts for confirmation. The code initializes data sources for dropdowns and handles user interactions through button clicks and double-click events.

Uploaded by

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

Coding CRUD

The document contains VBA code for user forms related to education and job positions in Excel. It includes functionalities for adding, deleting, and displaying data from a worksheet, with error handling and user prompts for confirmation. The code initializes data sources for dropdowns and handles user interactions through button clicks and double-click events.

Uploaded by

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

A.

CODING FORM UTAMA

Private Sub BukaJab_Click()

FORMJABATAN.Show

End Sub

Private Sub BUKAPEND_Click()

FORMPENDIDIKAN.Show

End Sub

Private Sub UserForm_Initialize()

On Error Resume Next

Sheet1.Select

pendidikan.RowSource = "Sheet1!A2:A" & Range("A" & Rows.Count).End(xlUp).Row

Jabatan.RowSource = "Sheet1!C2:C" & Range("C" & Rows.Count).End(xlUp).Row

End Sub

B. CODING FORM PENDIDIKAN

Private Sub HAPUS_Click()


Application.ScreenUpdating = False
If Me.pendidikan.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("A2:A100").Find(What:=Me.pendidikan.Value, LookIn:=xlValues)
Hapusdata.Offset(0, 0).ClearContents
Call MsgBox("Data berhasil dihapus", vbInformation, "Hapus Data")
Me.pendidikan.Value = ""
Call Urut_Pendidikan
On Error Resume Next
Sheet1.Select
formutama.pendidikan.RowSource = "Sheet1!A2:A" & Range("A" & Rows.Count).End(xlUp).Row

End If
End Sub

Private Sub tabeldata_DblClick(ByVal Cancel As MSForms.ReturnBoolean)


On Error GoTo Erwin
Me.pendidikan.Value = Me.tabeldata.Value
Exit Sub
Erwin:
Call MsgBox("Pilih data yang akan dihapus", vbInformation, "Pilih Data")

End Sub

Private Sub TAMBAH_Click()


Dim DPENDIDIKAN As Object
Set DPENDIDIKAN = Sheet1.Range("A100").End(xlUp)
If Me.pendidikan.Value = "" Then
Call MsgBox("Silahkan isi pendidikan terlebih dahulu", vbInformation, "Isi Pendidikan")
Else
DPENDIDIKAN.Offset(1, 0).Value = Me.pendidikan.Value
Call MsgBox("Pendidikan berhasil ditambah", vbInformation, "Isi Pendidikan")
On Error Resume Next
Sheet1.Select
tabeldata.RowSource = "Sheet1!A2:A" & Range("A" & Rows.Count).End(xlUp).Row
formutama.pendidikan.RowSource = "Sheet1!A2:A" & Range("A" & Rows.Count).End(xlUp).Row
Me.pendidikan.Value = ""
End If

End Sub
Private Sub UserForm_Initialize()
On Error Resume Next
Sheet1.Select
tabeldata.RowSource = "Sheet1!A2:A" & Range("A" & Rows.Count).End(xlUp).Row

End Sub

C. CODING FORM JABATAN

Private Sub HAPUS_Click()


Application.ScreenUpdating = False
If Me.JABATAN.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("c2:c100").Find(What:=Me.JABATAN.Value, LookIn:=xlValues)
Hapusdata.Offset(0, 0).ClearContents
Call MsgBox("Data berhasil dihapus", vbInformation, "Hapus Data")
Me.JABATAN.Value = ""
Call Urut_jABATAN
On Error Resume Next
Sheet1.Select
formutama.JABATAN.RowSource = "Sheet1!C2:C" & Range("C" & Rows.Count).End(xlUp).Row

End If
End Sub

Private Sub tabeldata_DblClick(ByVal Cancel As MSForms.ReturnBoolean)


On Error GoTo Erwin
Me.JABATAN.Value = Me.TABELDATA.Value
Exit Sub
Erwin:
Call MsgBox("Pilih data yang akan dihapus", vbInformation, "Pilih Data")

End Sub

Private Sub TAMBAH_Click()


Dim DJABATAN As Object
Set DJABATAN = Sheet1.Range("C100").End(xlUp)
If Me.JABATAN.Value = "" Then
Call MsgBox("Silahkan isi pendidikan terlebih dahulu", vbInformation, "Isi Pendidikan")
Else
DJABATAN.Offset(1, 0).Value = Me.JABATAN.Value
Call MsgBox("Pendidikan berhasil ditambah", vbInformation, "Isi Pendidikan")
On Error Resume Next
Sheet1.Select
TABELDATA.RowSource = "Sheet1!C2:C" & Range("C" & Rows.Count).End(xlUp).Row
formutama.JABATAN.RowSource = "Sheet1!C2:C" & Range("C" & Rows.Count).End(xlUp).Row
Me.JABATAN.Value = ""
End If

End Sub
Private Sub UserForm_Initialize()
On Error Resume Next
Sheet1.Select
TABELDATA.RowSource = "Sheet1!c2:c" & Range("C" & Rows.Count).End(xlUp).Row

End Sub

You might also like