Bergabung di Channel Kampus Office Klik!

Tombol Simpan dan Edit Interaktive VBA Excel

Tombol Simpan dan Edit Interactive - Perhatikan Gambar Gif di bawah.!! Tombol Simpan dan Edit Data berada pada satu CommandButton. Namun memiliki fungsi yang berbeda saat kondisi berbeda.
Please wait 0 seconds...
Scroll Down and click on Go to Link for destination
Congrats! Link is Generated
Please wait 0 seconds...
Scroll Down and click on Go to Link for destination
Congrats! Link is Generated
Tombol Simpan dan Edit Interactive - Perhatikan Gambar Gif di bawah.!! Tombol Simpan dan Edit Data berada pada satu CommandButton. Namun memiliki fungsi yang berbeda saat kondisi berbeda. Menggunakan motode ini akan menghemat penggunaan area UserForm. 

Tampilan tombol simpan dan edit dalam satu tombol terlihat aplikasi dibuat oleh programer profesional. Kita harus meniru gaya ini. Terlihat profesional itu penting.

Tombol Simpan dan Edit  Interaktive VBA Excel
Langkah-langkah membuat Tombol Simpan dan Edit Interaktive dengan VBA Excel
Buka Excel, Klik Developer dan Pilih Visual Basic atau tekan tombol Ctrl + F11

Tambahkan Userform1 dan Lengkapi komponen2 yang dibutuhkan sebagai berikut :
TextBox 
Textbox1, Textbox2 dan Textbox3 biarkan saja apa adanya tanpa mengedit lagi Propertiesnya. bisa di sesuaikan dengan selera anda sendiri juga..

Ganti Caption Label
Label1 Caption "NIS"
Label2 Caption "NAMA"
Label3 Caption "ALAMAT"

Ganti Caption CommandButton
CommandButton1 Caption "Edit/Save"
CommandButton2 Caption "Clear"
CommandButton3 Caption "Close"

ListBox
Tambahkan Satu Buah ListBox untuk menampilkan data yang ada pada database. Menampilkan data ke Listbox dapat dibaca pada posting : Tampilkan Data di ListBox di UserForm VBA Excel
  • Jika sudah membuat userform1 serta komponen-komponen yang dibutuhkan selanjutnya kita ngopi dulu dah yeah..!!! hehehe.. Next.....!!
  • Selanjutnya tambahkan atau Insert Modul1 dan Isikan dalam Modul1 Kode berikut ini 
Option Explicit

Dim id As Integer, i As Integer, j As Integer, flag As Boolean

Sub GetData()

If IsNumeric(UserForm1.TextBox1.Value) Then
    flag = False
    i = 0
    id = UserForm1.TextBox1.Value
 
    Do While Cells(i + 1, 1).Value <> ""
 
        If Cells(i + 1, 1).Value = id Then
            flag = True
            For j = 2 To 3
                UserForm1.Controls("TextBox" & j).Value = Cells(i + 1, j).Value
            Next j
        End If
     
        i = i + 1
     
    Loop
 
    If flag = False Then
        For j = 2 To 3
            UserForm1.Controls("TextBox" & j).Value = ""
        Next j
    End If
 
Else
    ClearForm
End If

End Sub

Sub ClearForm()

For j = 1 To 3
    UserForm1.Controls("TextBox" & j).Value = ""
Next j

End Sub

Sub EditAdd()

Dim emptyRow As Long

If UserForm1.TextBox1.Value <> "" Then
    flag = False
    i = 0
    id = UserForm1.TextBox1.Value
    emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
 
    Do While Cells(i + 1, 1).Value <> ""
 
        If Cells(i + 1, 1).Value = id Then
            flag = True
            For j = 2 To 3
                Cells(i + 1, j).Value = UserForm1.Controls("TextBox" & j).Value
            Next j
        End If
     
        i = i + 1
     
    Loop
 
    If flag = False Then
        For j = 1 To 3
            Cells(emptyRow, j).Value = UserForm1.Controls("TextBox" & j).Value
        Next j
    End If
 
End If

End Sub

  • Letakkan kode berikut ini pada UserForm1 dan sesuaikan saja dengan Komponen-komponen yang anda buat.
Option Explicit
Private Sub Label8_Click()
On Error Resume Next
ActiveWorkbook.FollowHyperlink "http://www.senbakusen.com"
ActiveWorkbook.Close savechanges:=True
End Sub

Private Sub UserForm_Initialize()
Call tambahNIS
Call DataList
'Tempatkan kode ini di userform_initial
Call RemoveCaption(UserForm1)
TextBox1.SetFocus
End Sub

Private Sub TextBox1_Change()
GetData
End Sub

Private Sub CommandButton1_Click()
EditAdd
End Sub

Private Sub CommandButton2_Click()
ClearForm
End Sub

Private Sub CommandButton3_Click()
Unload Me
End Sub


Sub tambahNIS()
'Tambahkan NIS/Nomor Reg Otomatis
Dim i As Integer
i = Sheet1.Range("A" & Rows.Count).End(xlUp).Text
TextBox1.Value = "000" & i + 1
End Sub

Sub DataList()
With ListBox1
.RowSource = "RData"
.ColumnCount = 3
.ColumnHeads = True
.ColumnWidths = "40, 100, 100"
End With
End Sub

Demikian Kode-kode Untuk membuat UserForm dengan Tombol Simpan dan Edit Lebih Interaktive. Semoga kode yang admin sajikan bisa menjadi referensi bagi yang sedang mencari informasi membuat aplikasi yang memiliki tombol dengan fungsi lebih dari satu.

Dapatkan berbagai macam contoh file penerapan kode dan Aplikasi karya Admin yang disajikan pada blog ini dengan menghubungi WA Admin dengan nomor : 0811-6822-023.

Jika anda memiliki pertanyaan, saran dan kritikan yang membangun untuk admin mohon dapat disampaikan pada kolom komentar yang tersedia dibawah artikel ini.

Getting Info...

5 komentar

  1. FATHURROJI
    Komentar ini telah dihapus oleh pengarang.
  2. WAH SANGAT BAGUS MAS ARTIKELNYA DAN SANGAT MEMBANTU UNTUK BELAJAR KAMI, TERIMA KASIH BANYAK ATAS SEMUA ARTIKELNYA
    1. Terimkasiha tas kunjungan dan komentar terbaiknya..
  3. Sangat mencerahkan, terus semangat berkarya abang
  4. 👍👍👍👍👍👍👍
Komentar Anda Sangat Menentukan Kelangsungan Blog ini
Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.