I need to clear the names of all named cells within a range before executing a procedure.
I've tried the following code with no success so far:
Sub EraseCellNames()
Worksheets("SheetA").Range("A1:G5").Select
Dim nName As Name
For Each nName In Names
If Not Intersect(Selection, Range(nName.Name)) Is Nothing Then
nName.Delete
End If
Next nName
End Sub
Any ideas?
Thanks in advance!
Try this one:
Sub EraseCellNames()
Dim nName As Name
Dim targetRng As Range
Set targetRng = Worksheets("SheetA").Range("A1:G5")
For Each nName In ThisWorkbook.Names
If nName.ValidWorkbookParameter Then
If targetRng.Parent.Name = nName.RefersToRange.Parent.Name Then
If Not Intersect(targetRng, nName.RefersToRange) Is Nothing Then nName.Delete
End If
End If
Next nName
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.