Excel: 写入整个 ListObject 列

Excel: write entire ListObject Column

我怎样才能简单地将数组中的值一次写入整个 ListObject 列(仅限数据行,不包括 header)?我找到了一个解决方案,但我认为它不是很好:

' needs: ActiveSheet with ListObject "Tabelle1",
' with second column heading "Spalte2" and 4 data rows
Sub WriteLoColumnTest()
    Dim lo As ListObject
    Set lo = ActiveSheet.ListObjects("Tabelle1")

    Dim va(1 To 4, 1 To 1) As Variant
    va(1, 1) = "a"
    va(2, 1) = "b"
    va(3, 1) = "c"
    va(4, 1) = "d"

    ' here it comes:
    lo.ListColumns("Spalte2") _
        .Range _
        .Resize(lo.ListRows.Count) _
        .Offset(1) _
        .Value2 = va
End Sub

我需要 .ListColumns.Range 来获取我的范围,需要 .Resize.Offset 来跳过标题行。有没有更简单的方法?

如果您只是在寻找一种更简单的方法来做到这一点,您可以使用下面的方法实现相同的效果

Sub WriteLoColumnTest()
    Dim lo As ListObject: Set lo = ActiveSheet.ListObjects("Tabelle1")
    Dim va As Variant

    va = Array("a", "b", "c", "d")
    lo.ListColumns("Spalte2").DataBodyRange.Value2 = Application.Transpose(va)
End Sub

为了进一步阅读,您可能需要熟悉列表对象的不同部分

https://www.thespreadsheetguru.com/blog/2014/6/20/the-vba-guide-to-listobject-excel-tables