Article ID: 131922
Article Last Modified on 6/11/2007
Sub Find_Names()
' Loop through all names in workbook.
For Each n In ActiveWorkbook.Names
' Set Error Handling so macro will not fail when it
' encounters a name that does not refer to a worksheet range.
On Error Resume Next
' Check to see if the name refers to the ActiveSheet.
If Mid(n.RefersTo, 2, InStr(n.RefersTo, "!") - 2) = _
ActiveSheet.Name Then
' If name refers to ActiveSheet, then find the intersection of the
' named range and the ActiveCell.
' If the ActiveCell is in the named range, "y" will equal "Range",
' otherwise y equals "".
Set y = Intersect(ActiveCell, Range(n.RefersTo))
' Display a message box if the ActiveCell is in the named range.
If TypeName(y) = "Range" Then MsgBox "Cell is in : " & n.Name
End If
Next
MsgBox "No More Names!" ' Display message when finished.
End SubLoops
163435 VBA: Programming Resources for Visual Basic for Applications
Additional query words: XL97 looping 8.0 XL
Keywords: kbdtacode kbhowto kbprogramming KB131922