Koding CRUD Lisview

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 4

Option Explicit

Sub NOMOROTOMATIS()
On Error Resume Next
Dim IdVal As Integer
IdVal = oto_LastRow(Sheets("DATA_SISWA"))
Me.TextBox1 = "NIK-521" & Format(IdVal, "0353000")
End Sub
Function oto_LastRow(ByVal Sht As Worksheet)
Dim lastRow As Long
Dim lRow As String
lastRow = Sht.Cells.SpecialCells(xlLastCell).Row
lRow = Sht.Cells.SpecialCells(xlLastCell).Row
Do While Application.CountA(Sht.Rows(lRow)) = 0 And lRow <> 1
lRow = lRow - 1
Loop
oto_LastRow = lRow
End Function
Sub Tampil()
Dim Item As ListItem
Dim ambildata As Integer
Dim i As Integer
ListView1.ListItems.Clear
ambildata = Sheet2.Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To ambildata
Set Item = ListView1.ListItems.Add(Text:=Sheet2.Cells(i, 1))
Item.SubItems(1) = Sheet2.Cells(i, 2)
Item.SubItems(2) = Sheet2.Cells(i, 3)
Item.SubItems(3) = Sheet2.Cells(i, 4)
Item.SubItems(4) = Sheet2.Cells(i, 5)
Next
Label6.Caption = ListView1.ListItems.Count
End Sub

Private Sub Bersihkan_Click()


Call KONDISIAWAL
End Sub

Private Sub Hapus_Click()


Dim Busek, DiBusek As String
Sheet2.Select
If Me.TextBox2.Text = "" Then
Call MsgBox("Pilih data terlebih dahulu", vbInformation, "Pilih Data")
Else
If MsgBox("Anda Yakin Akan Menghapus Data : " & TextBox2.Text, vbYesNo + 48,
"Aplikasi Data") = vbYes Then
DiBusek = Sheets("DATA_SISWA").Cells(Rows.Count, "A").End(xlUp).Row
Sheets("DATA_SISWA").Range("A2:A" & DiBusek).Find(What:=Me.ListView1.SelectedItem,
_
LookIn:=xlValues, LookAt:=xlWhole).Activate
Busek = ActiveCell.Row
Cells(Busek, 1).ClearContents
Cells(Busek, 2).ClearContents
Cells(Busek, 3).ClearContents
Cells(Busek, 4).ClearContents
Cells(Busek, 5).ClearContents
Call MsgBox("Data Berhasil diHapus Guys..!!!", vbInformation, "Hapus Data")
Call HapusBersih
MsgBox "Data Telah Di Hapus", 64, "Aplikasi Data"
End If
Call KONDISIAWAL
End If
End Sub
Sub HapusBersih()
Application.ScreenUpdating = False
Sheet2.Select
Sheet2.Range("A1:E20000").Sort Key1:=Range("A1"), Order1:=xlAscending,
Header:=xlYes
Application.ScreenUpdating = True
End Sub
Private Sub Save_Click()
With Worksheets("DATA_SISWA").Range("A2:A1000")
Dim rws As Long
Dim Ws As Object
Set Ws = Worksheets("DATA_SISWA")
Ws.Activate
rws = Ws.Cells(Ws.Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Ws.Cells(rws, 1) = TextBox1
Ws.Cells(rws, 2) = TextBox2
Ws.Cells(rws, 3) = TextBox3
Ws.Cells(rws, 4) = TextBox4
Ws.Cells(rws, 5) = TextBox5
End With
Call NOMOROTOMATIS
Call KONDISIAWAL
End Sub
Sub LoadListView()
Dim wksSource As Worksheet
Dim rngData As Range
Dim rngCell As Range
Dim LstItem As ListItem
Dim RowCount As Long
Dim ColCount As Long
Dim i As Long
Dim j As Long
Set wksSource = Worksheets("DATA_SISWA")
Set rngData = wksSource.Range("A1").CurrentRegion
For Each rngCell In rngData.Rows(1).Cells
Me.ListView1.ColumnHeaders.Add Text:=rngCell.Value, Width:=90
Next rngCell
RowCount = rngData.Rows.Count
ColCount = rngData.Columns.Count
For i = 2 To RowCount
Set LstItem = Me.ListView1.ListItems.Add(Text:=rngData(i, 1).Value)
For j = 2 To ColCount
LstItem.ListSubItems.Add Text:=rngData(i, j).Value
Next j
Next i
Label6.Caption = ListView1.ListItems.Count
End Sub
Private Sub Ubah_Click()
Dim Ubah
Dim Berubah As Range
Ubah = TextBox1.Text
If Me.TextBox2.Text = "" Then
Call MsgBox("Pilih data terlebih dahulu", vbInformation, "Pilih Data")
Else
Set Berubah = Range("A:A").Find(What:=Ubah)
Cells(Berubah.Row, 2) = TextBox2
Cells(Berubah.Row, 3) = TextBox3
Cells(Berubah.Row, 4) = TextBox4
Cells(Berubah.Row, 5) = TextBox5
Call KONDISIAWAL
End If
End Sub

Private Sub UserForm_Activate()


Do While Form1.Left > 220
Form1.Left = Form1.Left - 1.5
DoEvents
Loop
Do While Form1.Height < 463.5
Form1.Height = Form1.Height + 1
DoEvents
Loop
Do While Form1.Width < 703.5
Form1.Width = Form1.Width + 0.04
DoEvents
Loop

With Me.ListView1
.Gridlines = True
.HideColumnHeaders = False
.View = lvwReport
.FullRowSelect = True
End With
Call LoadListView
End Sub
Private Sub UserForm_Initialize()
Form1.Left = 1100
Form1.Height = 66
Call NOMOROTOMATIS
End Sub
Sub KONDISIAWAL()
TextBox1.Value = ""
TextBox2.Value = ""
TextBox3.Value = ""
TextBox4.Value = ""
TextBox5.Value = ""
Call Tampil
Call NOMOROTOMATIS
End Sub
Private Sub ListView1_ItemClick(ByVal Item As MSComctlLib.ListItem)
TextBox1 = ListView1.SelectedItem
TextBox2 = ListView1.SelectedItem.SubItems(1)
TextBox3 = ListView1.SelectedItem.SubItems(2)
TextBox4 = ListView1.SelectedItem.SubItems(3)
TextBox5 = ListView1.SelectedItem.SubItems(4)
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
Do While Form1.Height > 72
Form1.Height = Form1.Height - 1
DoEvents
Loop
Do While Form1.Left > -325
Form1.Left = Form1.Left - 1.5
DoEvents
Loop
Unload Me
End Sub

You might also like