Named Range?

M

Martin

Hello,

I have this code on the followhyperlink:

If ActiveCell.Address = "$B$6" Then Rows("11:110").EntireRow.Hidden = False

The rows 11 to 110 may change so I want to use named ranges but when I name
this range the code doesnt work. Is there a different way to reference the
named range?

Thanks in advance.

Martin
 
G

Gary''s Student

How about:

Sub dural()
If ActiveCell.Address = "$B$6" Then Range("myrange").EntireRow.Hidden = False
End Sub

where myrange is defined on the worksheet with:

Insert > Name
 
M

Martin

Thanks, worked perfectly. I hadnt defined the range using the insert | name
method

Martin
 
B

BSc Chem Eng Rick

Hi Martin

VB refers to ALL names defined in a worksheet as an object (Name object). To
use your specific name you need to call it by indexing in one of two ways.

1) Names are organised alphabetically and then indexed numerically i.e. if
you had "Apples", "Bananas" and "Oranges", then Apples is indexed as 1,
Bananas as 2 etc. If you wanteed to use apples in the VB code you would call
it as follows:
MyRange = Names (1).
I don't like this because if you add a name that comes before this one
alphabetically, I can't tell whether excel automatically reindexes so that
the code still refers to the right range.

2) Use the names object to call you range by its name:
MyRange = Names("Apples")

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top