0

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.

I'm stumped.

1 Answer 1

1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.