VBA merupakan Visual Basic of Application dimana VBA ini sangat membantu sekali dalam
mengolah data Excel. Jika Anda mahir Excel maka akan sangat hebat apabila dikolaborasikan
dengan kode-kode VBA. Jika Anda baru belajar tentang kode-kode VBA berikut contoh dasar kode
VBA excel bagi pemula.
Selecting
'==Kode VBA Memilih 2 baris ke bawah dan 2 kolom ke kanan:
Range(Selection, Selection.End(xlDown)).Select
'==Kode VBA Pilih dari sel saat ini untuk kolom terakhir dari daftar:
'==Kode VBA Pilih sel terakhir dari worksheet:
Range(Selection, Selection.End(xlToRight)).Select
Selection.SpecialCells(xlLastCell).Select
Pasting
'==Kode VBA Nilai rumus Paste, bukan rumus:
'==Kode VBA Paste ke dalam sel dan
memindahkan isi aslinya ke sel berikutnya:
Range("A3").Copy
Range("D26").PasteSpecial Paste:=xlValues
Selection.Insert Shift:=xlToRight
Selection.EntireColumn.Hidden = True
Columns("N:N").Insert
Selection.EntireRow.Insert
Selection.EntireRow.Delete Selection.EntireColumn.ColumnWidth = 10
Selection.Rows.AutoFit
Cell Formatting
'==Kode VBA Wrap Teks
'==Kode VBA Mengahpus warna
Selection.WrapText = False
Selection.Interior.ColorIndex = xlNone
AM/PM"
Selection.NumberFormat = "#,##0"
Selection.HorizontalAlignment = xlLeft
Selection.VerticalAlignment = xlBottom
Selection.IndentLevel = 3
Selection.ClearContents
Selection.Clear
Display
http://www.excel-id.com/2015/09/kumpulan-kode-vba-excel-dasar-yang.html 2/6
26/12/2018 Kumpulan Kode VBA Excel Dasar Yang Wajib Dipelajari | 300 Rumus Excel
Application.ScreenUpdating = False
Application.DisplayAlerts = False
hh:MM:ss")
[put other macro code here]
Range Names
'==Kode VBA menamai range
'==Kode VBA menuju ke alamat range
ActiveWorkbook.Names.Add Name:="Groups",
Range("Groups").Select
RefersTo:=Selection
Dim n as Object
Path/File Name
For Each n In ActiveWorkbook.Names
'==Kode VBA menyisimpan nama lokasi file
n.Delete
Next ActiveCell.Value = ActiveWorkbook.FullName
ActiveSheet.PageSetup.CenterFooter =
Pivot Tables
ActiveWorkbook.FullName
'===Kode VBA Menghapus item yang tidak
terpakai di tabel pivot ketika data telah berubah:
http://www.excel-id.com/2015/09/kumpulan-kode-vba-excel-dasar-yang.html 3/6
26/12/2018 Kumpulan Kode VBA Excel Dasar Yang Wajib Dipelajari | 300 Rumus Excel
Worksheets
Dim pt As PivotTable, ws As Worksheet '==Kode VBA Menambahkan tanggal untuk judul
setiap worksheet:
For Each ws In ActiveWorkbook.Worksheets
Semoga bermanfaat. dan untuk melihat contoh penggunaan kode VBA lebih lengkap silakan lihat
contoh Pembuatan Input Data dengan VBA
http://www.excel-id.com/2015/09/kumpulan-kode-vba-excel-dasar-yang.html 4/6
26/12/2018 Kumpulan Kode VBA Excel Dasar Yang Wajib Dipelajari | 300 Rumus Excel
End With
End Sub
Sheets1.Select
Sheet1.Visible = xlSheetVeryHidden
End Sub
http://www.excel-id.com/2015/09/kumpulan-kode-vba-excel-dasar-yang.html 5/6
26/12/2018 Kumpulan Kode VBA Excel Dasar Yang Wajib Dipelajari | 300 Rumus Excel
If ListBox1.Selected(i) Then
Private Sub ListBox1_AfterUpdate()
With ListBox2
Me.TextBox1.Value = Me.ListBox1.Column(0)
.AddItem
Me.TextBox2.Value = Me.ListBox1.Column(1)
For j = 0 To .ColumnCount - 1
Me.TextBox3.Value = Me.ListBox1.Column(2)
.List(.ListCount - 1, j) = ListBox1.List(i,
Me.TextBox4.Value = Me.ListBox1.Column(3)
j)
Me.TextBox5.Value = Me.ListBox1.Column(4)
Next j
End Sub
End With
End If
Next i Oke, segitu ajah dulu koleksi coding VBA
lengkap dan akan terus dilengkapi contoh-contoh
coding dasar VBA. Tunggu ajah ya update nya..
http://www.excel-id.com/2015/09/kumpulan-kode-vba-excel-dasar-yang.html 6/6