Vba 在excel中,如何识别其他工作表中未引用的命名范围
我有一个excel工作簿,在一个工作表上有数千个命名引用。是否有VBA代码可以告诉我这些引用中的哪些未在任何其他工作表的公式中使用,其中有25个以上。一次编辑。最后,我确实用了很多getridofnames谢谢你,蒂姆。我不得不修改它很多,它必须循环通过每一个工作表。这很麻烦,但我认为它是有效的 亚脊 将myName设置为名称 作为整数的Dim i 将fdMsg设置为字符串 将t作为布尔值Vba 在excel中,如何识别其他工作表中未引用的命名范围,vba,excel,named-ranges,Vba,Excel,Named Ranges,我有一个excel工作簿,在一个工作表上有数千个命名引用。是否有VBA代码可以告诉我这些引用中的哪些未在任何其他工作表的公式中使用,其中有25个以上。一次编辑。最后,我确实用了很多getridofnames谢谢你,蒂姆。我不得不修改它很多,它必须循环通过每一个工作表。这很麻烦,但我认为它是有效的 亚脊 将myName设置为名称 作为整数的Dim i 将fdMsg设置为字符串 将t作为布尔值 'Search for Sheet1 - If it doesnt exist create it Dim
'Search for Sheet1 - If it doesnt exist create it
Dim wsTest As Worksheet
Const strSheetName As String = "Sheet1"
Set wsTest = Nothing
On Error Resume Next
Set wsTest = ActiveWorkbook.Worksheets(strSheetName)
On Error GoTo 0
If wsTest Is Nothing Then
Worksheets.Add.Name = strSheetName
End If
'Clear all of Sheet1
Sheet1.Cells.Clear
i = 0
On Error Resume Next
fdMsg = ""
For Each myName In Names
t = False
For Each ws In ThisWorkbook.Worksheets
With ws
'Do not search Raw Data or Sheet 1 - or it has already been found
If ws.Name = "Sheet1" Or ws.Name = "Raw Data" Or t = True Then GoTo myNext
ws.Select
ws.Range("A1").Select
If Cells.Find(What:=myName.Name, _
After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False).Activate Is Nothing Then
' it was not found
Else
t = True ' it was found!
End If
myNext:
以
Next ws
If t = False Then
fdMsg = fdMsg & myName.Name & vbCr
Sheets("Sheet1").Range("A1").Offset(i, 0).Value = myName.Name
i = i + 1 'increment placement of found named ranges
t = False 'set test variable back to false
End If
Next myName
If fdMsg = "" Then
MsgBox "No unused names found in the workbook"
Else
MsgBox "Names Not Used:" & vbCr & fdMsg
End If
End Sub您自己编写了哪些VBA代码来实现您的目标?堆栈溢出不存在,其他人无法为您编写代码,它的存在是为了帮助您解决您编写的代码遇到的问题。我有一些代码可以帮助我识别命名范围,但我似乎找不到如何查找它们的引用方式。我正试图找到一种方法,将我拥有的excel电子表格从25MB缩小到更小的尺寸。我必须调整查询的输出,使其只返回我需要的数据。我并不是在寻找完整的代码,而是一个起点。