vba反映listview

时间:2017-01-05 12:47:03

标签: excel-vba vba excel

通过以下编码,我可以在listview中添加数据,但它正在添加来自excel的所有数据。很少有列包含敏感数据,我不想在listview上反映出来。请告知如何仅在列表视图中反映所选列的数据例如:列A,列C,列F,列G.

wksSource1.Activate
Set rngData = wksSource1.Range("A1").CurrentRegion
If II8 = 1 Then
    For Each rngCell In rngData.Rows(1).Cells
        Me.ListView4.ColumnHeaders.Add Text:=rngCell.Value, Width:=90
    Next rngCell
    II8 = 2
End If
RowCount = rngData.Rows.Count
ColCount = rngData.Columns.Count
For i = 2 To RowCount
    Set LstItem = Me.ListView4.ListItems.Add(Text:=rngData(i, 1).Value)
    For j = 2 To ColCount
        LstItem.ListSubItems.Add Text:=rngData(i, j).Value
    Next j
Next i

1 个答案:

答案 0 :(得分:0)

使用它:

dim RangeList$()
RangeList= VBA.SPLIT(    Selection.address, ",")

==>你可以在for循环中使用每个范围地址