Excel 中的示例数据:
A B C
1 9 5
2 4 y 3
3 1 9
4 66 4
5 5 9
我想做的是当我进入Y
在 B 列中,我想要“一些东西“ 执行。
- 我不认为
If Active.Cell = Y
将在这里工作,因为当我进入Y
然后按 Enter 键,active.cell
不会是我刚刚输入的那个Y
in.
-
循环 B 列将不起作用,因为
A。将会有多个Y
列中的 s
b.我需要执行“一些东西“进入后立即Y
进入一个细胞。
你能建议我应该尝试什么吗?
正如 siddarth 所建议的, Worksheet_change() 就是您正在寻找的。以下是您如何在没有任何泄漏的情况下完成任务。将此代码粘贴到您正在编辑 y 值的工作表中。
Private Sub Worksheet_Change(ByVal Target As Range)
Dim MyRng As Range
Set MyRng = Range("B:B")
Dim PieRng As Range
'Intersect will ensure your current cell lies on column B
Set PieRng = Intersect(Target, MyRng)
'if conditions to ensure trigger code only one cell edited on Col B and is 'y/Y'.
If Target.Columns.Count = 1 And Target.Rows.Count = 1 Then
If Not PieRng Is Nothing And LCase(Target.Text) = "y" Then
'Do my stuff here when y / Y are entered in Column B of current sheet
MsgBox "You entered " & Target.Value & " in Col B"
End If
End If
End Sub
如果失败请告诉我们...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)