¿Cómo puedo establecer un rango variable en una tabla en excel VBA 2007?

Estoy exportando un conjunto de datos semanalmente que debe configurarse como una tabla, sin embargo, habrá una cantidad variable de filas cada semana (las columnas no cambiarán).

Esto es lo que tengo hasta ahora:

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

Creo que mi problema es establecer el nuevo objeto de tabla en el rango new_table.

Estoy perplejo.

preguntado el 12 de junio de 14 a las 11:06

1 Respuestas

Quizás solo:

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

Respondido el 12 de junio de 14 a las 11:06

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.