Solved

Apply a user-defined table style to named ranges in one go

Posted on 2012-03-28
6
332 Views
Last Modified: 2012-09-18
Dear Experts:

I got a whole bunch of named ranges where I need to apply a user-defined table style in one go.

The ranges to which the user-defined table style has to be applied are named range_01, range_02, range_03 and so forth.

So, how can I apply this user-defined table style in one go to all these named ranges (workbook level scope names) ?

Thank you very much in advance.

I have attached a sample file with sample ranges / data tables along with user-defined table styles for your convenience.

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

Regards, Andreas

Regards, Andreas
ApplyTableStyle.xlsx
0
Comment
Question by:AndreasHermle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 12

Expert Comment

by:kgerb
ID: 37777971
We can probably do this at the same time we are searching and replacing :-)

Kyle
0
 
LVL 12

Accepted Solution

by:
kgerb earned 500 total points
ID: 37778032
Try this.  I think it will apply the formatting like you want.
Sub StyleAllNamedRanges()
Dim n As Name, sht As String
For Each n In ThisWorkbook.Names
    sht = Replace(Mid(n, 2, InStr(1, n, "!") - 2), "'", "")
    Sheets(sht).ListObjects.Add(xlSrcRange, Range(n), , xlYes).TableStyle = "styl_red_grey"
Next n
End Sub

Open in new window

Kyle

Correction:
Since your tables have headers I modified the final parameter to be xlYes instead of xlNo.
0
 

Author Comment

by:AndreasHermle
ID: 37778420
Hi Kyle,

this seems to work just fine. I'll do some more testing and then let you know.

Thank you very much for your swift and professional support.

Regards, Andreas
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:AndreasHermle
ID: 37779166
Hi Kyle,

I slightly changed/tweaked the code so that only specific named ranges are taken care of

Sub StyleAllNamedRanges()
Dim n As Name, sht As String
For Each n In ThisWorkbook.Names

If InStr(n.Name, "range_") > 0 Then
    sht = Replace(Mid(n, 2, InStr(1, n, "!") - 2), "'", "")
    Sheets(sht).ListObjects.Add(xlSrcRange, Range(n), , xlYes).TableStyle = "styl_red_grey"
End If
Next n
End Sub
0
 

Author Closing Comment

by:AndreasHermle
ID: 37779181
Concise, sophisticated coding.

Thank you very much for your professional help.

Regards, Andreas
0
 
LVL 12

Expert Comment

by:kgerb
ID: 37781520
You're welcome.  Glad to help.
Kyle
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question