excel - 单击单元格,通过链接图片显示数据范围
问题描述
第一次发帖,希望这一切都有意义。我在 excel 中创建了一个显示 88 行1的图形。在另一个工作表中,有几行数据记录了每行的内容2当在图形上单击一行时,我希望弹出另一个工作表中的相应数据3
我已经通过在每行上制作一个透明按钮/形状来隐藏和显示链接图像4来管理它。但是,我不得不为每行创建一个单独的按钮和宏,每行有 100 多行,这似乎效率很低。这是我使用的代码:
Sub LINE1A1()
With ActiveSheet.Shapes("Rectangle 9").TextFrame2.TextRange.Characters
If .Text = "Hide" Then
.Text = "Show"
ActiveSheet.Shapes("Picture 3").Visible = False
Else
.Text = "Hide"
With ActiveSheet.Shapes("Rectangle 9")
ActiveSheet.Shapes("Picture 3").Left = .Left + .Width
ActiveSheet.Shapes("Picture 3").Top = .Top + .Height
ActiveSheet.Shapes("Picture 3").Visible = True
End With
End If
End With
End Sub
实现这一目标的更好方法是什么?不是我使用链接图像作为数据和数据范围会发生变化,因为每行可能有超过 1 行数据。
解决方案
这是一个简单的例子,一个普通的 Sub 用来Application.Caller
确定是哪个形状触发了它。
Sub Tester()
Dim s As Shape, c, s2 As Shape
c = Application.Caller '<< name of your clicked shape
Debug.Print c
Set s = ActiveSheet.Shapes(c) '<< the clicked shape
With s.TextFrame2.TextRange.Characters
'here you need some way to transform the name of the clicked
' shape to get the name of the other shape to be shown/hidden/moved
Set s2 = ActiveSheet.Shapes(c & "_linked")
s2.Visible = (.Text = "Show")
.Text = IIf(.Text = "Show", "Hide", "Show") 'toggle text
End With
End Sub
推荐阅读
- mysql - 带有指标的 MySQL 查询审计日志
- node.js - 通过 ObjectId 发布到 db 中的嵌套数组
- sql - Big Query - 数据去识别 PII
- android - 应用程序在 PlayStore 中发布后谷歌地图空白显示
- lua - 全局“等待”不可调用(零值)
- reactjs - Material UI 5:由样式化实用程序定义的类在嵌套元素中不起作用
- c# - Dispatcher.BeginInvoke(new...ProgressBarProcess.Value = 1 没有显示?
- java - 我们正在使用 Java7,我正在尝试使用 yaml 生成 ApiClient 但存在编译问题
- android - 科特林 | 改造 API 使用 access_token 获取调用
- visual-studio-2022 - Visual Studio 2022 热重载问题