Sie sind auf Seite 1von 15

RUMUS LATIHAN FORM 4 VISUAL BASIC

Private Sub UserForm_Initialize()

Sheets("Customer").Select

Range("A1").Select

CMBBIDANG.List = Array("Transportasi", "Pertambangan", "Minyak & Gas Bumi", "Perkebunan", "Perikanan",


"Pertanian")

CMBKOTA.List = Array("Balikpapan", "Bontang", "Melak", "Samarinda", "Sangata", "Tenggarong")

TXTID.Value = ""

TXTNAMA.Value = ""

TXTDIREKTUR.Value = ""

CMBBIDANG.Value = ""

TXTALAMAT.Value = ""

CMBKOTA.Value = ""

OPTBALIKPAPAN = False

OPTBONTANG = False

OPTKUBAR = False

OPTKUKAR = False

OPTKUTIM = False

OPTSAMARINDA = False

TXTID.SetFocus

End Sub
Private Sub CmdDELETE_Click()

Tanya = MsgBox("Apakah Data Ini Ingin Dihapus? Yes/No ", vbYesNo + vbQuestion, "Delete Record")

If Tanya = vbYes Then

Selection.EntireRow.Delete

Call UserForm_Initialize

End If

End Sub

Private Sub CmdEXIT_Click()

Tanya = MsgBox("Apakah Anda Ingin Keluar Dari Program? Yes/No ", vbYesNo + vbQuestion, "Exit Program")

If Tanya = vbYes Then Unload Me

End Sub
Private Sub CMDSAVE_Click()

Range("A1").Select

If ActiveCell.Offset(1, 0).Value <> "" Then Selection.End(xlDown).Select

ActiveCell.Offset(1, 0).Select

ActiveCell.Value = TXTID.Value

ActiveCell.Offset(0, 1).Value = TXTNAMA.Value

ActiveCell.Offset(0, 2).Value = TXTDIREKTUR.Value

ActiveCell.Offset(0, 3).Value = CMBBIDANG.Value

ActiveCell.Offset(0, 4).Value = TXTALAMAT.Value

ActiveCell.Offset(0, 5).Value = CMBKOTA.Value

If OPTBALIKPAPAN = True Then

ActiveCell.Offset(0, 6).Value = "Balikpapan"

ElseIf OPTBONTANG = True Then

ActiveCell.Offset(0, 6).Value = "Bontang"

ElseIf OPTKUBAR = True Then

ActiveCell.Offset(0, 6).Value = "Kutai Barat"

ElseIf OPTKUKAR = True Then

ActiveCell.Offset(0, 6).Value = "Kutai Kartanegara"

ElseIf OPTKUTIM = True Then

ActiveCell.Offset(0, 6).Value = "Kutai Timur"

Else

ActiveCell.Offset(0, 6).Value = "Samarinda"

End If

Call UserForm_Initialize

End Sub
Private Sub CMDCHANGE_Click()

ActiveCell.Value = TXTID.Value

ActiveCell.Offset(0, 1).Value = TXTNAMA.Value

ActiveCell.Offset(0, 2).Value = TXTDIREKTUR.Value

ActiveCell.Offset(0, 3).Value = CMBBIDANG.Value

ActiveCell.Offset(0, 4).Value = TXTALAMAT.Value

ActiveCell.Offset(0, 5).Value = CMBKOTA.Value

If OPTBALIKPAPAN = True Then

ActiveCell.Offset(0, 6).Value = "Balikpapan"

ElseIf OPTBONTANG = True Then

ActiveCell.Offset(0, 6).Value = "Bontang"

ElseIf OPTKUBAR = True Then

ActiveCell.Offset(0, 6).Value = "Kutai Barat"

ElseIf OPTKUKAR = True Then

ActiveCell.Offset(0, 6).Value = "Kutai Kartanegara"

ElseIf OPTKUTIM = True Then

ActiveCell.Offset(0, 6).Value = "Kutai Timur"

Else

ActiveCell.Offset(0, 6).Value = "Samarinda"

End If

Call UserForm_Initialize

End Sub
Private Sub CMDCLEAR_Click()

Call UserForm_Initialize

End Sub
Private Sub CMDFIND_Click()

TXTID.Value = UCase(TXTID.Value)

Set FC = (Sheets("Customer").Columns("A").Find(What:=TXTID, MatchCase:=True, LookAt:=xlWhole))

If FC Is Nothing Then

MsgBox "Data Yang Dicari Tidak Ada, Silahkan Cari Yang Lain", vbOKOnly + vbInformation, "Find Record"

Else

Range(FC.Address).Select

TXTID = ActiveCell.Value

TXTNAMA = ActiveCell.Offset(0, 1).Value

TXTDIREKTUR = ActiveCell.Offset(0, 2).Value

CMBBIDANG = ActiveCell.Offset(0, 3).Value

TXTALAMAT = ActiveCell.Offset(0, 4).Value

CMBKOTA = ActiveCell.Offset(0, 5).Value

If ActiveCell.Offset(0, 6).Value = "Balikpapan" Then

OPTBALIKPAPAN = True

ElseIf ActiveCell.Offset(0, 6).Value = "Bontang" Then

OPTBONTANG = True

ElseIf ActiveCell.Offset(0, 6).Value = "Kutai Barat" Then

OPTKUBAR = True

ElseIf ActiveCell.Offset(0, 6).Value = "Kutai Kartanegara" Then

OPTKUKAR = True

ElseIf ActiveCell.Offset(0, 6).Value = "Kutai Timur" Then

OPTKUTIM = True

Else

OPTSAMARINDA = True

End If

End If

End Sub
Private Sub CMDFIRST_Click()

Range("A2").Select

TXTID = ActiveCell.Value

TXTNAMA = ActiveCell.Offset(0, 1).Value

TXTDIREKTUR = ActiveCell.Offset(0, 2).Value

CMBBIDANG = ActiveCell.Offset(0, 3).Value

TXTALAMAT = ActiveCell.Offset(0, 4).Value

CMBKOTA = ActiveCell.Offset(0, 5).Value

If ActiveCell.Offset(0, 6).Value = "Balikpapan" Then

OPTBALIKPAPAN = True

ElseIf ActiveCell.Offset(0, 6).Value = "Bontang" Then

OPTBONTANG = True

ElseIf ActiveCell.Offset(0, 6).Value = "Kutai Barat" Then

OPTKUBAR = True

ElseIf ActiveCell.Offset(0, 6).Value = "Kutai Kartanegara" Then

OPTKUKAR = True

ElseIf ActiveCell.Offset(0, 6).Value = "Kutai Timur" Then

OPTKUTIM = True

Else

OPTSAMARINDA = True

End If

End Sub
Private Sub CMDLAST_Click()

Range("A1").Select

Selection.End(xlDown).Select

TXTID = ActiveCell.Value

TXTNAMA = ActiveCell.Offset(0, 1).Value

TXTDIREKTUR = ActiveCell.Offset(0, 2).Value

CMBBIDANG = ActiveCell.Offset(0, 3).Value

TXTALAMAT = ActiveCell.Offset(0, 4).Value

CMBKOTA = ActiveCell.Offset(0, 5).Value

If ActiveCell.Offset(0, 6).Value = "Balikpapan" Then

OPTBALIKPAPAN = True

ElseIf ActiveCell.Offset(0, 6).Value = "Bontang" Then

OPTBONTANG = True

ElseIf ActiveCell.Offset(0, 6).Value = "Kutai Barat" Then

OPTKUBAR = True

ElseIf ActiveCell.Offset(0, 6).Value = "Kutai Kartanegara" Then

OPTKUKAR = True

ElseIf ActiveCell.Offset(0, 6).Value = "Kutai Timur" Then

OPTKUTIM = True

Else

OPTSAMARINDA = True

End If

End Sub
Private Sub CMDNEXT_Click()

If ActiveCell.Value = "" Then

ActiveCell.Offset(-1, 0).Select

ElseIf ActiveCell.Offset(1, 0).Value = "" Then

ActiveCell.Activate

Else

ActiveCell.Offset(1, 0).Select

End If

TXTID = ActiveCell.Value

TXTNAMA = ActiveCell.Offset(0, 1).Value

TXTDIREKTUR = ActiveCell.Offset(0, 2).Value

CMBBIDANG = ActiveCell.Offset(0, 3).Value

TXTALAMAT = ActiveCell.Offset(0, 4).Value

CMBKOTA = ActiveCell.Offset(0, 5).Value

If ActiveCell.Offset(0, 6).Value = "Balikpapan" Then

OPTBALIKPAPAN = True

ElseIf ActiveCell.Offset(0, 6).Value = "Bontang" Then

OPTBONTANG = True

ElseIf ActiveCell.Offset(0, 6).Value = "Kutai Barat" Then

OPTKUBAR = True

ElseIf ActiveCell.Offset(0, 6).Value = "Kutai Kartanegara" Then

OPTKUKAR = True

ElseIf ActiveCell.Offset(0, 6).Value = "Kutai Timur" Then

OPTKUTIM = True

Else

OPTSAMARINDA = True

End If

End Sub
Private Sub CMDPREVIEW_Click()

If ActiveCell.Value = "ID CUSTOMER" Then

ActiveCell.Offset(1, 0).Select

ElseIf ActiveCell.Offset(-1, 0).Value = "ID CUSTOMER" Then

ActiveCell.Activate

Else

ActiveCell.Offset(-1, 0).Select

End If

TXTID = ActiveCell.Value

TXTNAMA = ActiveCell.Offset(0, 1).Value

TXTDIREKTUR = ActiveCell.Offset(0, 2).Value

CMBBIDANG = ActiveCell.Offset(0, 3).Value

TXTALAMAT = ActiveCell.Offset(0, 4).Value

CMBKOTA = ActiveCell.Offset(0, 5).Value

If ActiveCell.Offset(0, 6).Value = "Balikpapan" Then

OPTBALIKPAPAN = True

ElseIf ActiveCell.Offset(0, 6).Value = "Bontang" Then

OPTBONTANG = True

ElseIf ActiveCell.Offset(0, 6).Value = "Kutai Barat" Then

OPTKUBAR = True

ElseIf ActiveCell.Offset(0, 6).Value = "Kutai Kartanegara" Then

OPTKUKAR = True

ElseIf ActiveCell.Offset(0, 6).Value = "Kutai Timur" Then

OPTKUTIM = True

Else

OPTSAMARINDA = True

End If

End Sub
Private Sub UserForm_Initialize()

Sheets(“Barang”).Select

Range(“A1”).Select

For n = 0 To 5

Frame1 (n).Value = “”

Next n

TXTKODE.SetFocus

Lstbarang.Value = ‘’’

End Sub
Private Sub CMDCLEAR_Click()

Call UserForm_Initialize

End Sub

Private Sub CMDDELETE_Click()

Tanya = MsgBox("Apakah Data Ini Ingin Dihapus? Yes/No", vbYesNo + vbQuestion, "Delete Record")

If Tanya = vbYes Then

Selection.EntireRow.Delete

Call UserForm_Initialize

End If

End Sub

Private Sub CmdEXIT_Click()

Tanya = MsgBox("Apakah Anda Ingin Keluar Dari Program? Yes/No ", vbYesNo + vbQuestion, "Exit Program")

If Tanya = vbYes Then Unload Me

End Sub

Private Sub CMDFISRT_Click()

Range("A2").Select

txtkode.Value = ActiveCell.Value

End Sub

Private Sub CMDLAPORAN_Click()

Unload Me

UserForm3.Show

End Sub

Private Sub CMDLAST_Click()

Range("A1").Select

Selection.End(xlDown).Select

txtkode.Value = ActiveCell.Value

End Sub

Private Sub CMDNEXT_Click()

If ActiveCell.Value = "" Then


ActiveCell.Offset(-1, 0).Select

ElseIf ActiveCell.Offset(1, 0).Value = "" Then

ActiveCell.Activate

Else

ActiveCell.Offset(1, 0).Select

End If

txtkode.Value = ActiveCell.Value

End Sub

Private Sub CMDPREVIEW_Click()

If ActiveCell.Value = "KODE BARANG" Then

ActiveCell.Offset(1, 0).Select

ElseIf ActiveCell.Offset(-1, 0).Value = "KODE BARANG" Then

ActiveCell.Activate

Else

ActiveCell.Offset(-1, 0).Select

End If

txtkode.Value = ActiveCell.Value

End Sub

Private Sub CMDSTORE_Click()

If txtkode.Value = "" Then

MsgBox "Kode Barang Masih Kosong!", vbOKOnly + vbInfomation, "Save Record"

ElseIf ActiveCell.Value = txtkode.Value Then

For n = 1 To 5

ActiveCell.Offset(0, n).Value = Frame1(n).Value

Next n

Else

Range("A1").Select

If ActiveCell.Offset(1, 0) <> "" Then Selection.End(xlDown).Select

ActiveCell.Offset(1, 0).Select
For n = 0 To 5

ActiveCell.Offset(1, n).Value = Frame1(n).Value

Next n

Call UserForm_Initialize

End If

End Sub

Private Sub CMDTRANSAKSI_Click()

Unload Me

UserForm2.Show

End Sub

Private Sub UserForm_Initialize()

Sheets("Barang").Select

Range("A1").Select

For n = 0 To 5

Frame1(n).Value = ""

Next n

txtkode.SetFocus

Lstbarang.Value = ""

End Sub

Private Sub LstBARANG_Click()

txtkode.Value = Lstbarang.Value

End Sub

Private Sub TXTKODE_Change()

txtkode.Value = UCase(txtkode.Value)

Set fc = (Worksheets("Barang").Columns("A").Find(what:=txtkode, MatchCase:=True, lookat:=xlWhole))

If fc Is Nothing Then

For n = 1 To 5

Frame1(n).Value = ""

Next n
Lstbarang.Value = ""

Else

Range(fc.Address).Select

For n = 1 To 5

Frame1(n).Value = ActiveCell.Offset(0, n).Value

Next n

Lstbarang.Value = txtkode.Value

End If

End Sub

Das könnte Ihnen auch gefallen