Loop through named range list

vib500

I found a lot of examples but it's not working in my case and I don't know why. Very basic code:

Sub Test()
Dim namCur As Name

For Each namCur In ActiveSheet.Names
MsgBox "Name: " & namCur.Name & ", Refers To: " & namCur.RefersTo
Next namCur
End Sub

And I have the same issue when I use Worksheets("Assumptions").Names

When I watch ActiveSheet.Name, this is correct I get "Assumptions", you can see on the picture below the list of named ranges. But I never get the MsgBox and the For loop goes directly to the end. Edit: Very important, I need to loop only this sheet's named ranges, not the whole workbook Any idea?

Printscreen

I use Excel 2016

CLR

Your solution will only list Names that have a scope set to only the ActiveSheet.

Change this

For Each namCur In ActiveSheet.Names

To this

For Each namCur In ThisWorkBook.Names

to list all names in the Workbook. You can then check the RefersTo address to check if it applies to the ActiveSheet.

Sub Test()

Dim namCur As Name
Dim TargetSheetName As String

TargetSheetName = "Assumptions"

For Each namCur In ThisWorkbook.Names

    If Range(namCur.RefersTo).Parent.Name = TargetSheetName Then MsgBox "Name: " & namCur.Name & ", Refers To: " & namCur.RefersTo

Next namCur

End Sub

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

For Loop through Named Range cells names

From Dev

How to loop through a list of files that are sequentially named?

From Dev

How to loop through named cells and list value for each

From Dev

How to loop through named cells and list value for each

From Dev

How to correctly loop through range and list to create Pandas Dataframe?

From Dev

Loop through range

From Dev

Loop through Range Areas

From Dev

Populate list box with a named range

From Dev

putting a unique list in a named range

From Dev

How to loop through a list of input range sliders in the DOM and capture values with an each loop

From Dev

Looping through multiple named ranges and going to similar named range VBA

From Dev

Looping through multiple named ranges and going to similar named range VBA

From Dev

How to loop through an IP range?

From Dev

Excel/VBA - Loop through range

From Dev

Range for loop through forwarded iterable

From Dev

Loop through each workbook in a range

From Dev

Initializer list in a range for loop

From Dev

Initializer list in a range for loop

From Dev

Refer to Named Range from Cell Value in For Loop

From Dev

R: loop through list

From Dev

loop through a list of properties

From Dev

Loop Through Self List

From Dev

going through a list with a for loop

From Dev

For Each Function, to loop through specifically named worksheets

From Dev

Excel VBA Loop Through Named Ranges

From Dev

python for loop cycles through value not in range specified

From Dev

loop through range object excel c#

From Dev

Perl: Loop through months in a specified range

From Dev

Running through entire range of `unsigned char` in `for` loop

Related Related

HotTag

Archive