PDA

View Full Version : [SOLVED:] Unable to locate named range in code



visyouall
01-25-2016, 10:29 AM
I am new to Excel VBA. I have been given a large Excel file with several macros and I am tracing the code flow. My understanding of this code:


Worksheets("ABC").Activate
Range("abc_name").Select


is that the sheet ABC should get the focus and that some range on this sheet must already have been already named "abc_name" somewhere in the code. However, I cannot find the string "abc_name" anywhere in any of the modules that affect this workbook.

Advice is appreciated.

visyouall
01-25-2016, 11:03 AM
The range was named in the Excel file itself. I was mistakenly under the impression that the code was responsible for creating this workbook but it simply receives it, as is, and operates on it.

SamT
01-25-2016, 08:39 PM
Dim Nme As object
For each Nme in ThisWorkbook.Names
MsgBox Nme.Name & " Refers to " & Nme.
Next

ThisWorkbook.Names.Add Name:="MyRangeName", RefersTo:="=Sheet1!A1:A3"

For each Nme in ThisWorkbook.Names
If Nme.RefersTo = "=Sheet1!A1:A3" Then MsgBox Nme.Name
Next