(Solved) – Create a table with a macro

  • by
(solved)-–-create-a-table-with-a-macro

I have this simple range:

enter image description here

I want to create a macro which creates a table from a range. The macro I get is this:

Sub Macro1()
'
' Macro1 Macro
'

'
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Application.CutCopyMode = False
    ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1:$B$3"), , xlYes).Name = _
        "Table12"
    ActiveCell.Range("Table12[#All]").Select
End Sub

The problem is that I want the macro to not be contingent on a specific size. I for instance want it to be able to work with this table as range aswell:

enter image description here

The problem in the code seems that it uses “$A$1:$B$3” but it should be independent of that. Is there a simple way to fix this? How can I record the macro so that it works for all tables?

Leave a Reply

Your email address will not be published. Required fields are marked *