Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Name Range in Excel

Status
Not open for further replies.

Groves22

Technical User
Jan 29, 2009
102
US
I'm sure this is an easy fix, but I keep getting an error when I run the following code:

Code:
    With Sheets("Paste Area")
        .Cells(1, width + 3).Value = .Cells(2, width + 3).Value - .Cells(2, 21).Value
        [b].Cells(1, width + 3).Name.Add Name:="dist_to_unit_year"[/b]

How to fix this?

Thanks!
 


hi,
Code:
    With Sheets("Paste Area")
        .Cells(1, width + 3).Value = .Cells(2, width + 3).Value - .Cells(2, 21).Value
        With .Cells(1, width + 3)
            ThisWorkbook.Names.Add _
                Name:="dist_to_unit_year", _
                RefersTo:="=" & .Parent.Name & "!" & .Address

        End With
    End With

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Hey Skip...

I don't get the error, but it doesn't name the range. Why would that be?

Thanks
 

If you check out the VBA HELP example for the Names Object Add Method, you will see...
Code:
    ActiveWorkbook.Names.Add _
        Name:="tempRange", _
        RefersTo:="=Sheet1!$A$1:$D$3"
The Object reference of the Names Add Method, is the workbook object. The RANGE referece is applied to the RefersTo Property, and is in standard Excel Worksheet range format as a string, ie =SheetName!RangeReference

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top