This is my sample data.

[![enter image description here](https://i.stack.imgur.com/ZMFpI.png)](https://i.stack.imgur.com/ZMFpI.png)

And this is the VBA code produced with macro.

```
Sub Macro1()
'
' Macro1 Macro
'

'
    Range("A1:C3").Select
    Application.CutCopyMode = False
    ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1:$C$3"), , xlYes).Name = _
        "Table1"
    Range("Table1[#All]").Select
    ActiveSheet.ListObjects("Table1").TableStyle = "TableStyleMedium9"
End Sub

```

How do I get the macro code?

1. Developer > Record Macro
2. Select all (ctrl + A) inside any cells within `A1:C3`
3. Home > Format as Table

Output

[![enter image description here](https://i.stack.imgur.com/MPDsu.png)](https://i.stack.imgur.com/MPDsu.png)

The problem is my data is dynamic and not necessarily stay at `A1:C3`.

It could be bigger or smaller.

E.g., let say I've bigger within range `A1:C4` in different Ms Excel file.

[![enter image description here](https://i.stack.imgur.com/Sczsu.png)](https://i.stack.imgur.com/Sczsu.png)

The code above won't select all, instead it selects only `A1:C3`.

[![enter image description here](https://i.stack.imgur.com/9cNT9.png)](https://i.stack.imgur.com/9cNT9.png)

Last row `A4:C4` won't be affected with this code.

How do I change this doesn't matter how big the table is?