编辑将过滤的表添加到ListBox对象

时间:2017-09-29 11:01:44

标签: excel excel-vba vba

我试图只将表的可见行添加到ListObject。但是,代码无法正常运行。

编辑:感谢Rory的纠正。我现在得到的错误是代码1004,调试器指向" ListBox1.List(I,1)= y.Range(1)"

以下是代码:

Private Sub UserForm_Activate()
Dim TagArray As Variant
TagArray = Split(Me.Tag, "-") 'This userform takes the worksheet and table 
name from another userform
Dim x As Variant, y As Range, I As Long
Set x = Worksheets(TagArray(0)).ListObjects(TagArray(1)).Range.SpecialCells(xlCellTypeVisible)
    For Each y In x
        I = y.Row
        ListBox1.List(I, 1) = y.Range(1) 
        ListBox1.List(I, 2) = y.Range(2) 
        ListBox1.List(I, 3) = y.Range(3) 
        ListBox1.List(I, 4) = y.Range(4) 
        ListBox1.List(I, 5) = y.Range(5) 
        ListBox1.List(I, 6) = y.Range(6) 
        ListBox1.List(I, 7) = y.Range(7) 
        ListBox1.List(I, 8) = y.Range(8) 
        ListBox1.List(I, 9) = y.Range(9) 
        ListBox1.List(I, 10) = y.Range(10) 'I could probably use a for loop here. Not critical at this point though.
    Next
End Sub

非常感谢任何帮助,谢谢。

0 个答案:

没有答案