Changing Excel Data into a Table

Saperblue56

New Member
Joined
Aug 14, 2017
Messages
9
Hi all,
Is it Possable, using VBA to Change normal Data into a Table?

Code:
ActiveSheet.ListObjects.Add(xlSrcRange, ("$A$1:$O$") & LastRow, , xlYes).Name = "Table1"
     ActiveSheet.ListObjects("Table1").TableStyle = "TableStyleLight2"

So far I Have the above code, but become an timeout Error 5, it does say in German what is wrong, but this would be the wrong Forum for that, cann any one put me on the right road?

Ray
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
The second argument should be a range:

Code:
ActiveSheet.ListObjects.Add(xlSrcRange, Range("A1:O" & LastRow), , xlYes).Name = "Table1"
 
Upvote 0
Well firstly Thanks for taking your Time for me RoryA

I tried your Idea :-
Code:
Dim Dws As Worksheet
Dim rngLastRow As Long
     Set Dws = ThisWorkbook.Sheets("Basis Daten Inclusive Kommentar")
         
    With Dws
        rngLastRow = .Range("A" & .Rows.Count).End(xlUp).Row
    End With
ActiveSheet.ListObjects.Add(xlSrcRange, Range("A1:O" & LastRow), , xlYes).Name = "Table1"
ActiveSheet.ListObjects("Table1").TableStyle = "TableStyleLight2"
but now I get a runtime error 9
Index out of range is a very rough Translation

any Ideas
Ray
 
Upvote 0
OK, well your variable name is not what you posted so it's actually:

Code:
ActiveSheet.ListObjects.Add(xlSrcRange, Range("A1:O" & rngLastRow), , xlYes).Name = "Table1"

but the error you are getting suggests that the sheet name is incorrect. Though why you would use a rng prefix for a Long variable I'm not sure.
 
Last edited:
Upvote 0
:) Hi Rory,
How do You Know All This? sorry I dident get back earlyer, but I was on The Road through Europa.
You were right! the Name of the Sheet was the Problem, I wasent Aware that there are Restrictions ! as I shortend it, it works Perfect

Code:
ActiveSheet.ListObjects.Add(xlSrcRange, Range("A1:O" & DataLastRow), , xlYes).Name = "Table1"
ActiveSheet.ListObjects("Table1").TableStyle = "TableStyleLight2"
    
    Range("A1").Select

I wish you all a very nice weekend

Ray
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,335
Members
452,636
Latest member
laura12345

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