Excel VBA - 在特定 Non-Default(A1) 位置创建 Table
Excel VBA - Creating a Table In a Specific Non-Default(A1) Location
如果您运行以下代码:
WorkSheet.ListObjects.add(SourceType:=xlSrcRange, Destination:=Range("A10:C13"))
人们可能会想,这会将 table 置于 "A10:C13" 的范围内。不是,而是在A1中插入一列一行的table(不包括header):
这个函数的Official Documentation中明确说明了这一点:
The Destination argument is ignored if SourceType is set to
xlSrcRange.
如何将 table 插入任何其他单元格区域?
使用 this page 提供的文档,我模拟了用户可能会添加 table:
Range("A10:C13").Select
WorkSheet.ListObjects.add(SourceType:=xlSrcRange)
似乎添加 select 语句会将 table 放置到正确的位置。
您将工作表范围定义添加到错误的参数中。
WorkSheet.ListObjects.add SourceType:=xlSrcRange, Source:=WorkSheet.Range("A10:C13")
有关该方法的完整说明,请参阅 ListObjects.Add Method (Excel)。
如果您运行以下代码:
WorkSheet.ListObjects.add(SourceType:=xlSrcRange, Destination:=Range("A10:C13"))
人们可能会想,这会将 table 置于 "A10:C13" 的范围内。不是,而是在A1中插入一列一行的table(不包括header):
这个函数的Official Documentation中明确说明了这一点:
The Destination argument is ignored if SourceType is set to xlSrcRange.
如何将 table 插入任何其他单元格区域?
使用 this page 提供的文档,我模拟了用户可能会添加 table:
Range("A10:C13").Select
WorkSheet.ListObjects.add(SourceType:=xlSrcRange)
似乎添加 select 语句会将 table 放置到正确的位置。
您将工作表范围定义添加到错误的参数中。
WorkSheet.ListObjects.add SourceType:=xlSrcRange, Source:=WorkSheet.Range("A10:C13")
有关该方法的完整说明,请参阅 ListObjects.Add Method (Excel)。