All good except...

  • Thread starter Thread starter Rhonda
  • Start date Start date
R

Rhonda

It now gets to ThisWorkbook.Names(RngName).Delete and
comes back with Object defined error, any idea?

Almost there....



What does the string RngName hold?

Is there a name (Insert => Name => Define) on worksheets
(2)/Sheet2 with that
name?

Does Worksheets(2) have a tab name of sheet2 (is Sheet2
the second sheet in
the tab order).

If all of the above meets expectations, then the code
should work.

--
Regards,
Tom Ogilvy




message
 
Demonstrating from the immediate window:

Range("A1:A200").Name = "ABCD"
? Thisworkbook.Names(1).Name
ABCD
rngName = "ABCD"
? Thisworkbook.Names(rngName).RefersToRange.Address
$A$1:$A$200
thisWorkbook.Names(rngName).Delete


So thisworkbook.Names(rngName).Delete will work fine if you give it a valid
name.

See what the value of rngName is before you delete and see if there is a
name that matches rngName.

I ran test code form another sheet to delete a name:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
rngName = "Name1"
ThisWorkbook.Names(rngName).Delete
End Sub


That worked fine as well.

I believe the problem has something to do with your environment - the syntax
of the code appears OK.
 
Back
Top