vba convert dynamic range to tabe

already

Board Regular
Joined
Nov 11, 2008
Messages
179
Hello

I want to convert with vba a growing (dynamic) range into a table.

But I can't figure it out.

thanks in advance for your help

Kind regards

Al
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Try
Code:
Dim rng As Range
    
    Set rng = Range("A1").CurrentRegion 'Change to match your range
    
    ActiveSheet.ListObjects.Add(xlSrcRange, rng, , xlYes).Name = "MyTable"
 
Upvote 0
Re: vba convert dynamic range to table

Hello

When updated my table with new data my lookup function changed and the table name in my formula is changed by an error #ref!.

How can I resolve this ?

1/ I remove the old table
2/ I replace it with the new one import range convert it to table with same name and same sheet name than the old one

lookup formula change from =IFERROR(VLOOKUP(A292;mytable;3;0);"") into =IFERROR(VLOOKUP(A292;#REF!;3;0);"")

Kind regards

Al
 
Upvote 0
Re: vba convert dynamic range to table

Looks like your formula doesn't find the mytable. Check the name of the table. Looks like VBA doesn't always need a reason to change the table name into something else: I changed my original code to name the tables using the sheet name and still the names were sometimes slightly different even when there were no other tables on the sheet (and that macro creates a single Table on the sheet anyway).

If you're using macros you might as skip the table and use an event macro to name your new range with the old name every time your data range expands. - Or use the good old OFFSET-function to define the named range without having to use any VBA. Both these ways make sure the name doesn't change.
 
Upvote 0
Try
Rich (BB code):
Dim rng As Range
 
    Set rng = Range("A1").CurrentRegion 'Change to match your range
 
    ActiveSheet.ListObjects.Add(xlSrcRange, rng, , xlYes).Name = "MyTable"


I would think the code should work like:
Rich (BB code):
Dim rng As Range
 
    Set rng = Range("A1").CurrentRegion 'Change to match your range
    rng.Name = "MyTable"

I use code like this without any trouble
 
Upvote 0
thanks again misca for your help
thanks arkusm this little code did the trick waah !!!

Kind regards
Al
 
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,517
Members
449,088
Latest member
RandomExceller01

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
Back
Top