循环使用名称并删除不符合指定模式的那些 [英] loop through names and delete those not matching specified pattern
问题描述
但是我有一个问题,我无法解决或找到答案,但我认为如果你知道如何解决应该是相当简单的。 (所以希望有人在那里做。)
问题:
当我导入表单时,我还会导入很多不必要的命名范围。我试图通过运行一个删除它们的宏来删除它们,而不删除我指定的宏,但是它可以为我工作。
任何帮助都非常赞赏
Sub DeleteNames()
Dim myName As Name
For This myName In ThisWorkbook。名称
如果myName<> 塔和_
myName<> 鸟然后
myName.Delete
结束如果
下一个
结束Sub
您需要使用名称对象的 namelocal 属性。 >
尝试这样:
Sub DeleteNames()
Dim myName As Name
For This myName In ThisWorkbook.Names
如果myName.NameLocal<> Tower和myName.NameLocal<> 鸟然后
myName.Delete
结束如果
下一个
结束Sub
I have a Excel workbook in which I import sheets from several other workbooks and then merge the data from these into an "overview" sheet. I am fairly new to vba so this task has taken quite some time, and alot of research. However I have one problem that i cant solve or find an answer to, but i think it should be fairly simple to solve if you know how. (so hopefully someone out there do.) Problem: When i import the sheets i also import a lot of unwanted named ranges. I have attempted to remove these by running a macro that deletes them without deleting those i specify, but it dosnt work for me.
Any help is much appreciated
Sub DeleteNames()
Dim myName As Name
For Each myName In ThisWorkbook.Names
If myName <> "Tower" And _
myName <> "Bird" Then
myName.Delete
End If
Next
End Sub
You need to use the namelocal property of the name object.
Try this:
Sub DeleteNames()
Dim myName As Name
For Each myName In ThisWorkbook.Names
If myName.NameLocal <> "Tower" And myName.NameLocal <> "Bird" Then
myName.Delete
End If
Next
End Sub
这篇关于循环使用名称并删除不符合指定模式的那些的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!