excel - 在用户表单标签中使用活动单元格值
问题描述
如何在用户窗体的标签中使用 target.value?无论我尝试了什么,我都会遇到错误。(运行时“438”:对象不支持属性或方法)
我希望用户窗体在更改单元格编号时显示:
我的工作表代码:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
Set KeyCells = Range("D8:D12")
If Not Application.Intersect(KeyCells, Target) Is Nothing Then
UserForm1.Show
End If
End Sub
我的用户窗体代码按照我想象的方式工作(但它不起作用):
Private Sub UserForm_Initialize()
Label1.Caption = Worksheets("Personal Barrier").Target.Offset(0, -1).Value
End Sub
解决方案
对象中没有Target
属性Worksheet
。您可以在方法中设置标签Worksheet_Change
:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
Set KeyCells = Range("D8:D12")
If Not Application.Intersect(KeyCells, Target) Is Nothing Then
UserForm1.Label1.Caption = Target.Offset(0, -1).Value
UserForm1.Show
End If
End Sub
推荐阅读
- php - 是否有最小 PHP upload_max_size 限制
- javascript - 如何在 vue.js 中获取子元素的 vue 实例?
- python - 将字符串拆分为保持换行符的句子
- asp.net - .net core backgroundservice 等效于 asp.net
- tensorflow - tensorflow keras评估函数运行时间过长
- cmake - cmake CMAKE_SYSTEM_LIBRARY_PATH not setup properly cmake version 3.7.2
- javascript - 在 JS 画布中绘制正弦波没有任何作用
- python - 有没有办法将 ListModel 的内容从 QML 获取到 pyqt?
- python - Pip 仅安装包的依赖项,而不是包本身
- oracle - MAC OS 上的端口关闭,无法运行 docker 映像