VBA Excel选择以字符开头的命名范围 [英] VBA Excel select named range starting with character
本文介绍了VBA Excel选择以字符开头的命名范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对命名范围有一个小问题.
I've got a little problem with named ranges.
我在不同的图纸上有多个命名范围.我想用vba隐藏显示所有这些范围.命名范围的示例:r1_name1.另一张纸上的第二个是r1_name2.因此,所有范围都以前面相同的代码开头:r1_.
I have multiple named ranges on different sheets. i would like to hide of show all those ranges with vba. example of named range: r1_name1 . the 2nd on another sheet is r1_name2. So all the ranges starts with the same code in front: r1_ .
我如何遍历以r1_开头的所有范围并隐藏/或显示它们?
How can i loop through all ranges that starts with r1_ and hide/or show them?
推荐答案
要遍历命名范围:
Sub tgr()
Dim NamedRange As Name
For Each NamedRange In ActiveWorkbook.Names
If LCase(Left(NamedRange.Name, 3)) = "r1_" Then
MsgBox NamedRange.Name & Chr(10) & _
Range(NamedRange.RefersTo).Address(External:=True)
End If
Next NamedRange
End Sub
隐藏/取消隐藏它们:
Range(NamedRange.RefersTo).EntireRow.Hidden = True 'or False
这篇关于VBA Excel选择以字符开头的命名范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文