Resize Listobject Table dynamically with VBA

前端 未结 3 1826
遇见更好的自我
遇见更好的自我 2020-12-15 20:41

I want to change the size of the object tables through VBA, I tried modifying the code from MSDN about the listobject.resize method, but I want to dynamically i

相关标签:
3条回答
  • 2020-12-15 20:50

    The problem is Range("A1" & Lrow1) returns a Range of $A$112, because you are passing the Range function the result of the catenation of "A1" & "12".

    Try replacing this line:

    ob.Resize Range("A1" & Lrow1)
    

    With this one:

    ob.Resize ob.Range.Resize(Lrow1)
    
    0 讨论(0)
  • 2020-12-15 20:52

    There's way avoiding calculating last row:

    Sub ResizeListDyn()
        Dim tbl As ListObject
        Set tbl = ActiveSheet.ListObjects(1)
        tbl.Resize tbl.Range.CurrentRegion
    End Sub
    
    0 讨论(0)
  • 2020-12-15 21:10

    If you need to resize only the row-dimension:

    Dim tbl As ListObject
    
    Set tbl = ActiveSheet.ListObjects("YourTableName")
    With tbl.Range
        tbl.Resize .Resize(.CurrentRegion.Rows.Count) 'NOTE: unlike the Range.Resize proprty, the Table.Resize
                                                      'method's argument is a Range object (not a size spec).
    End With
    

    Resizing only the column-dimension would be symmetrical:

    With tbl.Range
        tbl.Resize .Resize(, .CurrentRegion.Columns.Count)
    End With
    
    0 讨论(0)
提交回复
热议问题