Solved

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

Posted on 2012-03-28
6
342 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
Independent Software Vendors: 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

690 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