我正在尝试使用工作表的双击事件来填充表单中的文本框,其中包含双击行中特定列的值。
e.g。
我有四列
val input: TypedPipe[Person] = ....
input
.map(_.getName.split(" "))
当我双击列ID Name Age Gender
1 A 24 M
2 B 26 F
3 C 22 F
4 D 30 M
中的任何单元格时,会弹出一个带有文本框的表单,其中的文本框中填充了行中Name
列中的值,该值为点击。因此,当我双击列名称中的“B”时,表格应弹出文本框值“F”。
到目前为止这是我的代码
Gender
答案 0 :(得分:2)
使用名为frm_Update
的表单和三个适当命名的文本框控件
这将获取Target
行,第2,3和4列的值,并将值放在文本框中:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim oForm As frm_Update
If Target.Column = 2 Then
Set oForm = New frm_Update
Cancel = True
With oForm
.txtName = Cells(Target.Row, 2)
.txtAge = Cells(Target.Row, 3)
.txtGender = Cells(Target.Row, 4)
.Show
End With
End If
End Sub
@Comintern - 我将很好地阅读该链接。我真正应该付诸实践的所有东西。
答案 1 :(得分:0)
我使用双击事件打开表单& form activate event从活动单元格行中的列中获取值
所以基本上
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, CANCEL As Boolean)
CANCEL = True
If Target.Column = 2 Then Exit Sub
Update.Show
End Sub
Private Sub UserForm_Activate()
Dim r As Long
r = ActiveCell.Row
Me.TextBox1.value = Cells(r, 4).value