如何在用户表单的标签中使用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
Worksheet
对象中没有Target
属性。您可以在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