|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Option Explicit
- '窗体加载
- Private Sub UserForm_Initialize()
- Dim arr As Variant
- arr = Worksheets("Sheet1").Range("A1").CurrentRegion.Value
-
- '调用 listViewLoad 过程,传参 arr
- Call ListViewLoad(arr)
- End Sub
- 'ListView 加载 要一个数组参数
- Private Sub ListViewLoad(ByVal arr)
- Dim i As Integer, iCount As Integer, subIndex As Integer, iSub As Integer
-
- With Me.ListView_UserList '引用listView
- .FullRowSelect = True '行全选
- .View = lvwReport '报表视图
- .Gridlines = True '显示网格线
- .Font.Size = 11 '设置字体大小
- .Font.Name = "微软雅黑" '设置字体
-
- With .ColumnHeaders '引用列标题
- .Clear '清除旧的列标题
- iCount = UBound(arr, 2) - LBound(arr, 2) + 1 '计算列数
- For i = LBound(arr, 2) To UBound(arr, 2) '循环数组的第一行
- '新增一个列标题
- With .Add
- .Width = Me.ListView_UserList.Width / iCount '用 ListView 的宽度除以列数,取平均宽度。
- .Text = arr(LBound(arr, 1), i)
- End With
- Next i
- End With
-
- '循环数据
- For i = LBound(arr, 1) + 1 To UBound(arr, 1)
- '引用 ListItems.Add 添加数据行
- With .ListItems.Add
- .Text = arr(i, 1) '数据行的第一列
-
- subIndex = 1
- '数据行的第二列至最后一列
- For iSub = LBound(arr, 2) + 1 To UBound(arr, 2)
- .SubItems(subIndex) = arr(i, iSub)
- subIndex = subIndex + 1
- Next iSub
- End With
- Next i
- End With
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|