Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Conditional Formatting to HIghlight named ranges - error


Function InNamedRanges(Optional inCell As Range) As String

Dim myName As Name
Dim myAddress As String
Dim myMessage As String
Dim myRange As Range
Dim inRange As Integer

If inCell Is Nothing Then Set inCell = Application.Caller
Hi Folks,

trying to get Excel 2003 to highlight all named ranges in a sheet.
Ranges are defined self-adjusting (using offset... count), and I want
users to be able to see at any given point what area they cover.

My approach was to use conditional formatting, and putting in a
VBA-created formula there that would output TRUE if cell was in a named
range, and FALSE if not.

I've had a look at a number of entries in this and other groups, but
none of the examples they give seem to work. Here is my function:

Function isInNamedRange(inCell As Range)

For Each myName In ActiveWorkbook.Names
Debug.Print myName.Name; myName.RefersTo
myAddress = myName.RefersTo
If Not Application.Intersect(inCell, Range(myAddress)) Is Nothing
Then isInNamedRange = True: Exit Function
Next myName
isInNamedRange = False

End Function


Excel gives a #VALUE message if I use this in a sheet, and the
debug.print statement only prints out the line it gets to before the
intersect bit. I am clueless - any help?

Thanks in advance!
Malte

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Conditional Formatting to HIghlight named ranges - error

Function isInNamedRange(inCell As Range)
Dim myName as Name, rng as Range
Dim myAddress as String
For Each myName In ActiveWorkbook.Names
Debug.Print myName.Name; myName.RefersTo
myAddress = myName.RefersTo
On Error Resume Next
set rng = myName.RefersToRange
On Error goto 0
if not rng is nothing then
if inCell.Parent.Name = rng.Parent.Name then
If Not Application.Intersect(inCell, rng) Is Nothing Then _
isInNamedRange = True: Exit Function
end if
end if
Next myName
isInNamedRange = False
End Function

--
Regards,
Tom Ogilvy



"Malte Nuhn" wrote in message
oups.com...

Function InNamedRanges(Optional inCell As Range) As String

Dim myName As Name
Dim myAddress As String
Dim myMessage As String
Dim myRange As Range
Dim inRange As Integer

If inCell Is Nothing Then Set inCell = Application.Caller
Hi Folks,

trying to get Excel 2003 to highlight all named ranges in a sheet.
Ranges are defined self-adjusting (using offset... count), and I want
users to be able to see at any given point what area they cover.

My approach was to use conditional formatting, and putting in a
VBA-created formula there that would output TRUE if cell was in a named
range, and FALSE if not.

I've had a look at a number of entries in this and other groups, but
none of the examples they give seem to work. Here is my function:

Function isInNamedRange(inCell As Range)

For Each myName In ActiveWorkbook.Names
Debug.Print myName.Name; myName.RefersTo
myAddress = myName.RefersTo
If Not Application.Intersect(inCell, Range(myAddress)) Is Nothing
Then isInNamedRange = True: Exit Function
Next myName
isInNamedRange = False

End Function


Excel gives a #VALUE message if I use this in a sheet, and the
debug.print statement only prints out the line it gets to before the
intersect bit. I am clueless - any help?

Thanks in advance!
Malte



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Conditional Formatting to HIghlight named ranges - error

Thank you Tom - this does the job! I would never have come up with the
parent<< idea!


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
Sum of named ranges conditional to date? SleazyBreezy Excel Worksheet Functions 25 June 24th 09 10:46 AM
Named ranges are causing a #REF error Arlen Excel Discussion (Misc queries) 3 July 30th 08 10:18 PM
Conditional formatting to highlight the lowest valid value PaladinWhite Excel Worksheet Functions 1 March 25th 08 11:35 PM
Conditional Named Ranges Tevuna Excel Worksheet Functions 2 September 5th 07 02:58 PM
Conditional Sum Wizard with dynamic named ranges willee Excel Worksheet Functions 4 February 5th 06 07:03 PM


All times are GMT +1. The time now is 04:16 PM.

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"