Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default Finding all Similarly Named Ranges?

Hi

I have a workbook in which I have defined similar named ranges in may named
worksheets, they all start with "H1_Server". What I am trying to do is code
a procedure that will go through all the named worksheets in the workbook,
selecting the named range if found, and then applying arbitary formatting
(lets just say change the background color to green).

Can anyone out there help?

Many Thanks - Grant


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default Finding all Similarly Named Ranges?

Hi

In my workbook I have two named worksheets, "Extract" and "Info".

On the worksheet "Extract" I have three named Ranges, "H1_Server_1",
"H1_Server_2", "H1_Server_3"

On the worksheet "Extract" I have three named Ranges, "H1_Server_4",
"H1_Server_5", "H1_Server_6"

I need to fashion a script that will locate any named range starting with
"H1_Server_" on any worksheet and then change the background color of the
named ranges.

This is the code that I have at the moment but it only seems to work on the
worksheet "Extract".

Sub FormatH1()
Dim nm As String
Dim x As Integer
Dim strH1 As String

strH1 = "H1_Server_"

For x = 1 To ActiveWorkbook.Names.Count
On Error GoTo lineend:
nm = ActiveWorkbook.Names(x).Name
If InStr(nm, strH1) Then
Range(nm).Select
With Selection.Interior
.ColorIndex = 35
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
End If
Next
lineend:
End Sub

What am I doing wrong/missing? Any help will be much appreciated.

Thanks - Grant


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,489
Default Finding all Similarly Named Ranges?

Hi Grant,

Your code will only do the named ranges on the active sheet because this
line Range(nm).Select generates an error if the sheet is not active.

This revised code will do the formatting without using Select or Selection

Sub FormatH1()
Dim namTemp As Name
Dim strH1 As String
strH1 = "H1_Server_*"
For Each namTemp In ActiveWorkbook.Names
If namTemp.Name Like strH1 Then
With namTemp.RefersToRange.Interior
.ColorIndex = 35
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
End If
Next
End Sub

Cheers
Andy


Grant Reid wrote:

Hi

In my workbook I have two named worksheets, "Extract" and "Info".

On the worksheet "Extract" I have three named Ranges, "H1_Server_1",
"H1_Server_2", "H1_Server_3"

On the worksheet "Extract" I have three named Ranges, "H1_Server_4",
"H1_Server_5", "H1_Server_6"

I need to fashion a script that will locate any named range starting with
"H1_Server_" on any worksheet and then change the background color of the
named ranges.

This is the code that I have at the moment but it only seems to work on the
worksheet "Extract".

Sub FormatH1()
Dim nm As String
Dim x As Integer
Dim strH1 As String

strH1 = "H1_Server_"

For x = 1 To ActiveWorkbook.Names.Count
On Error GoTo lineend:
nm = ActiveWorkbook.Names(x).Name
If InStr(nm, strH1) Then
Range(nm).Select
With Selection.Interior
.ColorIndex = 35
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
End If
Next
lineend:
End Sub

What am I doing wrong/missing? Any help will be much appreciated.

Thanks - Grant



--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default Finding all Similarly Named Ranges?

Hi Grant,

Grant Reid wrote:
In my workbook I have two named worksheets, "Extract" and "Info".

On the worksheet "Extract" I have three named Ranges, "H1_Server_1",
"H1_Server_2", "H1_Server_3"

On the worksheet "Extract" I have three named Ranges, "H1_Server_4",
"H1_Server_5", "H1_Server_6"

I need to fashion a script that will locate any named range starting with
"H1_Server_" on any worksheet and then change the background color of the
named ranges.


try this:

Sub FormatH1()
Const strH1 As String = "H1_Server_"
Dim nName As Name

For Each nName In ActiveWorkbook.Names
If InStr(nName.Name, strH1) Then _
Range(nName).Interior.ColorIndex = 35
Next nName
End Sub


--
Regards

Melanie Breden
- Microsoft MVP für Excel -

http://excel.codebooks.de (Das Excel-VBA Codebook)

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default Finding all Similarly Named Ranges?

Many Thanks to all who replied.

Regards - Grant




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Like 123, allow named ranges, and print named ranges WP Excel Discussion (Misc queries) 1 April 8th 05 06:07 PM
Named Ranges Donna Excel Discussion (Misc queries) 3 February 1st 05 11:35 PM
Similarly helpful AccessVB forum? universal[_26_] Excel Programming 6 January 31st 04 10:42 PM
Named Ranges Neal[_5_] Excel Programming 3 October 23rd 03 02:09 PM
Named Ranges and VBA Add-ins Tom Ogilvy Excel Programming 0 September 4th 03 09:58 PM


All times are GMT +1. The time now is 02:05 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"