[英]How can I set a variable range to a table in excel VBA 2007?
I am exporting a data set weekly that needs to be set as a table, however there will be a varying number of rows each week (columns will not change). 我每周导出一个需要设置为表格的数据集,但是每周会有不同数量的行(列将保持不变)。
Here is what I have so far: 这是我到目前为止的内容:
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
I believe my problem is setting the new table object to the new_table range. 我相信我的问题是将新表对象设置为new_table范围。
I'm stumped. 我很沮丧
Perhaps just: 也许只是:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.