Perintah Command Button Visual Basic

Revisi Untuk teman Kita  Tommy  yang sedang belajar Visual basic Sedikit keluar dari Pascal, sedikit ngulas tentang Command Button di Visual Basic, untuk kode command buttonnya sudah saya perbaiki. Bagaimana caranya menghapus data yang ada di Cell yang kita inginnkan, disini kita ingin menghapus Cel A1. Berikut tampilan ketika sebelum dan sesudah Command Button di Klik.

Visual Basic Visual Basic command button

Untuk Perintah di Command Buttonnya, berikut di bawah.

Private Sub btntambah_Click()
    Dim rangeSheet1 As Range
    For i = 1 To Sheet1.Rows.Count
    Set rangeSheet1 = Range(“A” & i)
    If Len(rangeSheet1.Value) = 0 Then
    rangeSheet1.Value = txtnama.Text
    Exit For
    End If
    Next i
    txtnama.Value = “”
End Sub

Perintah di Button Hapus

Private Sub btnHapus_Click()
    Dim rangeSheet1 As Range
    btntambah.Enabled = False
    For i = 1 To Sheet1.Rows.Count
    Set rangeSheet1 = Range(“A” & i)
    If Len(rangeSheet1.Value) > 0 Then
    
    rangeSheet1.EntireRow.Delete
    Else
    Exit For
    End If
    Next i
    btntambah.Enabled = True
    btntambah.SetFocus      
End Sub

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s