Apply a table style to a named range

Dear Experts:

I got a named range called 'MyRange' (workbook level scope name) in the current workbook.

On the current worksheet I would like to apply a built-in table style ("TableStyleLight1") to that named range using VBA.

How is this done?

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
Andreas HermleTeam leaderAsked:
Who is Participating?
 
andrewssd3Connect With a Mentor Commented:
I think your range would have to be a table in order to be able to apply a table style to it.  This code creates a table in range "MyRange", then applies the style.  You could omit the first line if your range is already defined as a table, and you may need to change the name "Table1" if you have called it something else.
    ActiveSheet.ListObjects.Add(xlSrcRange, Range("MyRange"), , xlGuess).Name = "Table1"
    ActiveSheet.ListObjects("Table1").TableStyle = "TableStyleLight1"

Open in new window

0
 
Andreas HermleTeam leaderAuthor Commented:
Great help. thank you very much andrew. Works just fine.

Regards, Andreas
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.