My goal is to list all names in my workbook which are not referenced in a formula. Here's my code so far:
Sub FindUnusedNames()
Dim Nm, lngLast As Long, rng As Range
For Each Nm In ThisWorkbook.Names
lngLast = Sheets("UnusedNames").Range("A1048576").End(xlUp).Row + 1
Set rng = Cells.Find(What:=Nm, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False)
If Not rng Is Nothing Then
Else
Sheets("UnusedNames").Range("A" & lngLast).Value = Nm
End If
Next
End Sub
It bombs on the Set rng line. The goal is to iterate through all names in ThisWorkbook.Names and list those not referenced in a formula or in a cell value on the worksheet named UnusedNames.
Bookmarks