Menu

Selasa, 13 Desember 2016

Memasukan Data Textbox ke ListView dengan Tombol pada UserForm

Private Sub CmdTambahListviuw_Click()
Dim lvwItem As ListItem
With ListView1
Set lvwItem = .ListItems.Add(, , TextBox1.Value)
lvwItem.SubItems(1) = TextBox2.Value
lvwItem.SubItems(2) = TextBox3.Value
End With
End Sub

Dan untuk nampilkan semua data dalam ListView

Private Sub UserForm_Activate()
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("Sheet1")
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
End Sub