我每周导出一个需要设置为表的数据集,但每周会有不同数量的行(列不会更改)。
这是我到目前为止所做的:
Sub Eformat_as_table()
Dim project_count As Integer
Dim new_table As Range
project_count = 0
For a = 1 To 10000
If Cells(a, 1) = "" Then
Else
project_count = project_count + 1
End If
Next a
ThisWorkbook.Sheets("format sheet").Range(Cells(1, 1), Cells(project_count, Columns.Count).End(xlToLeft)).Name = "Table"
Set new_table = Range("Table")
ActiveSheet.ListObjects.Add(xlSrcRange, Range(new_table), , xlYes).Name = _
"Table2"
ActiveSheet.ListObjects("Table2").TableStyle = "TableStyleMedium1"
End Sub
我相信我的问题是将新表对象设置为new_table范围。
我很难过。
答案 0 :(得分:1)
也许只是:
Sub Eformat_as_table()
With ThisWorkbook.Sheets("format sheet")
.ListObjects.Add(SourceType:=xlSrcRange, Source:=.Cells(1).CurrentRegion, _
XlListObjectHasHeaders:=xlYes, TableStyleName:="TableStyleMedium1").Name = "Table2"
End With
End Sub