View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
JE McGimpsey JE McGimpsey is offline
external usenet poster
 
Posts: 4,624
Default A bit of help with Names, please?

If you made your name a worksheet level name (i.e., included the sheet
name in the "Name in workbook" field:

Sheet1!MyName

(only "MyName" will appear in the Name box, but Insert/Name/Define will
show the worksheet in the list) then the name contains the sheet
reference and your Left(nm,4) won't pick it up.

Note that you can use the .RefersToRange property once you find the
name, rather than resolving it with the Range() method:

Set rng = nm.RefersToRange




In article ,
"Ed" wrote:

(Using XL2000) I selected a range and used InsertNameDefine to add the
name. It shows up in the Name box in the top left, and can be selected from
there.

I was trying to select the range using
For Each nm In wkb.Names
If Left(nm, 4) = "Calc" Then
Set rng = Range(nm)
End If

but it kept coming up with an error. So I inserted a Debug.Print for every
name, and the name was not there!

Two questions, then:
(1) How do I set the name of a range so my code will see it?
(2) Since the Name belongs to the Book object, but the Range belongs to the
Sheet object, am I setting the range properly?

Ed