problem in deleting the named ranges

M

Maya

Can anyone please let me know how to delete the named ranges of those
worksheets which have been deleted from the workbook.I have noticed that when
we delete the sheets, named ranges referening to those sheets donot get
deleted cos of this the size of the workbook gets increase .Is there any
event which will fire while deleting the sheet from the workbook.

thanksin advance for any of the suggestion.
 
M

Mike H

Try this:-

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim nName As Name
For Each nName In Names
If InStr(1, nName.RefersTo, "#REF!") > 0 Then
nName.Delete
End If
Next nName
End Sub

Mike
 

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