Dynamic Range Selection when inserting a Table [MACROS]

An Quala

Board Regular
Joined
Mar 21, 2022
Messages
126
Office Version
  1. 2021
Platform
  1. Windows
Hello,

When I am recording a macro, in the start I have to insert a table to all the available data but when I am doing it is always in the fixed range, I want to make it dynamic instead, what is the best possible way to do that?

Rich (BB code):
Sub Macro2()
'
' Macro2 Macro
'

'
    Range("A1").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Application.CutCopyMode = False
    Application.CutCopyMode = False
    ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1:$AQ$380"), , xlYes).Name = _
        "Table3"
    Range("C2").Select
    ActiveCell.FormulaR1C1 = "1"
    Range("C2").Select
    Selection.AutoFill Destination:=Range("Table3[Operation]")
    Range("Table3[Operation]").Select
    Range("F10").Select
End Sub
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
20,504
Office Version
  1. 365
Platform
  1. Windows
You can use the CurrentRegion property of the Range object to define your dynamic range . . .

VBA Code:
    With ActiveSheet
        .ListObjects.Add(xlSrcRange, .Range("A1").CurrentRegion, , xlYes).Name = "Table1"
    End With

For more information, see the following reference . . .


Hope this helps!
 

Forum statistics

Threads
1,175,761
Messages
5,899,328
Members
434,762
Latest member
JAZ91

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top