使用单元格双击事件更改userform文本框值

时间:2015-12-17 16:22:12

标签: vba excel-vba excel

我整个上午一直在寻找答案,但没有提出解决方案。我想在双击事件后更改userform1上的textbox1的值。我一直得到方法或数据成员未找到错误。如何从双击事件中完成此操作?

Public Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Worksheets("Offense").Range("A:A")) Is Nothing Then
    Cancel = True
    DataCollectionFormValid.Show
    Me.RowNumber.Value = ActiveCell.Row ' error here
End If
End Sub

1 个答案:

答案 0 :(得分:1)

Me是指运行代码的对象,在这种情况下是工作表,而不是用户表单。你需要:

Public Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Worksheets("Offense").Range("A:A")) Is Nothing Then
    Cancel = True
    With DataCollectionFormValid
      .RowNumber.Value = ActiveCell.Row
      .Show
    End With
End If
End Sub