excel - 是否可以获得活动单元格所在范围的名称?
问题描述
场景: Range 被命名为“Dog”,命名的 Range Dog 指的是 A1:D4。活动单元格位于指定范围内的单元格 B3 中。
是否可以获得活动单元格所在的命名范围的名称?即返回名称“狗”?
解决方案
可能类似于以下内容,它测试Intersection
和ActiveCell
每个命名范围。
On Error Resume Next
...On Error GoTo 0
是必要的,因为当和命名范围在不同的工作表上时,或者如果不是命名范围但它引用常量或公式时,Intersect
它将失败。ActiveCell
n
Sub test()
Dim n As Name
For Each n In ActiveWorkbook.Names
Dim rng As Range
Set rng = Nothing
On Error Resume Next
Set rng = Intersect(ActiveCell, n.RefersToRange)
On Error GoTo 0
If Not rng Is Nothing Then
Debug.Print n.Name
End If
Next
End Sub
推荐阅读
- powerbi - 用于排除结果的 PowerBI 切片器
- javascript - 类型错误:无法读取未定义的属性“配置”
- r - Using FOR loop to fill in a data from in R (code review)
- android - Configuring the host in server to be accessible to external devices
- asp.net-mvc - texbox 值未显示在 url
- c# - 将 BSON 流解码为人类可读的字符串
- html - Mailchimp:内部带有条件合并标签块的无序列表?
- f# - F#从两个列表中创建对列表
- reactjs - 如何在 Android 完整证明示例中从网络加载反应原生 JS 包?
- java - 确定哪种类型的异常是可抛出的