NCC*_*NCC 3 excel vba excel-vba
我在如何将包含多个列和行的范围中的数据放入列表框时遇到问题.
假设我有一个范围rng我尝试了多个列和行:
如果我尝试addItem rng(i,j),那么一切都将在1列中.
我也试过.list但它也没用.
这是你在尝试什么?
Option Explicit
Private Sub CommandButton1_Click()
Dim ws As Worksheet
Dim rng As Range
Dim i As Long, j As Long, rw As Long
Dim Myarray() As String
'~~> Change your sheetname here
Set ws = Sheets("Sheet1")
'~~> Set you relevant range here
Set rng = ws.Range("A1:E5")
With Me.ListBox1
.Clear
.ColumnHeads = False
.ColumnCount = rng.Columns.Count
ReDim Myarray(rng.Rows.Count, rng.Columns.Count)
rw = 0
For i = 1 To rng.Rows.Count
For j = 0 To rng.Columns.Count
Myarray(rw, j) = rng.Cells(i, j + 1)
Next
rw = rw + 1
Next
.List = Myarray
'~~> Set the widths of the column here. Ex: For 5 Columns
'~~> Change as Applicable
.ColumnWidths = "50;50;50;50;50"
.TopIndex = 0
End With
End Sub
Run Code Online (Sandbox Code Playgroud)
快照
归档时间: |
|
查看次数: |
29689 次 |
最近记录: |