The syntax for referring to named ranges is Range("{Name of Named
Range}"). Also, I would strong recommend to work with Option Explicit
which will require you to explicitly declare your variables. That
makes your code easier to read and maintain. Give this a try:

Option Explicit

Private Sub Worksheet_Activate()
    Dim c As Range
    Dim a As String
    With Range("CompNames")
        Set c = .Find(Range("A1"))
        If Not c Is Nothing Then a = Sheets("Names").Cells(c.Row, 3)
    End With
    If ActiveSheet.Name <> a Then ActiveSheet.Name = a
End Sub

Hope this helped,
Rolf Jaeger
SoarentComputing
http://soarentcomputing.com/SoarentComputing/ExcelSolutions.htm


On Dec 2, 8:59 pm, Dave Bonallack <davebonall...@hotmail.com> wrote:
> Hi friends,
>
> I am using XL2003.
>
> I am having trouble using a named range in a macro, even after refering the 
> Help.
> The named range lives in the active workbook.
> My code is this:
>
> Private Sub Worksheet_Activate()
>     With [CompNames]
>         Set c = .Find(Range("A1"))
>         If Not c Is Nothing Then A = Sheets("Names").Cells(c.Row, 3)
>     End With
>     If ActiveSheet.Name <> A Then ActiveSheet.Name = A
> End Sub
>
> You will see that I have had to resort to using [ ] around the named range, 
> which is the only way I could get the code to run.
> I tried With Range("CompNames") which is what the Help seemed to indicate, 
> and tried including the sheet name and the workbook name, but none of those 
> worked.
>
> I have checked the spelling of the named range, even copied and pasted it 
> straight from the name box.
>
> When I use With Range("CompNames") it returns the following error:
>
> Runtime error '1004':
> Method 'Range' of object '_Worksheet' failed
>
> Anyone had a problem with this before?
>
> Regards - Dave.
>
> _________________________________________________________________
> Use Messenger in your Hotmail inbox Find out 
> howhttp://windowslive.ninemsn.com.au/hotmail/article/823454/web-im-for-h...

-- 
----------------------------------------------------------------------------------
Some important links for excel users:
1. Excel and VBA Tutorials(Video and Text), Free add-ins downloads at 
http://www.excelitems.com
2. Excel tutorials at http://www.excel-macros.blogspot.com
3. Learn VBA Macros at http://www.vbamacros.blogspot.com
4. Excel Tips and Tricks at http://exceldailytip.blogspot.com
 

To post to this group, send email to excel-macros@googlegroups.com
If you find any spam message in the group, please send an email to:
Ayush Jain  @ jainayus...@gmail.com or
Ashish Jain @ 26may.1...@gmail.com
<><><><><><><><><><><><><><><><><><><><><><>
HELP US GROW !!

We reach over 6,500 subscribers worldwide and receive many nice notes about the 
learning and support from the group. Our goal is to have 10,000 subscribers by 
the end of 2009. Let friends and co-workers know they can subscribe to group at 
http://groups.google.com/group/excel-macros/subscribe

Reply via email to