循环使用名称并删除不符合指定模式的那些 [英] loop through names and delete those not matching specified pattern

查看:164
本文介绍了循环使用名称并删除不符合指定模式的那些的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Excel工作簿,我从其他工作簿中导入工作表,然后将这些数据合并到概述表中。我对vba来说是相当新的,所以这个任务已经花了相当长的时间,并进行了大量的研究。
但是我有一个问题,我无法解决或找到答案,但我认为如果你知道如何解决应该是相当简单的。 (所以希望有人在那里做。)
问题:
当我导入表单时,我还会导入很多不必要的命名范围。我试图通过运行一个删除它们的宏来删除它们,而不删除我指定的宏,但是它可以为我工作。



任何帮助都非常赞赏

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆