当某个单元格的值=“1”时,按下组合键(例如Ctrl + Alt + x)

我希望计算机在Excel工作表中的某个单元格(例如A1)的值改变为某个值(例如“1”)后自动按下某个组合键(例如Ctrl + Alt + x)。 我在网上查了几个小时,但是找不到和我的情况完全一样的信息。 请帮助和感谢很多。

我敢肯定,你不需要input组合键,但是如果你真的想要SendKeys 。 此代码将执行许多操作,具体取决于使用SendKeys命令完成的单元格A1中input的值:

 'Fires when you change a value on the sheet. Private Sub Worksheet_Change(ByVal Target As Range) 'Was only a single cell selected? If Target.Cells.Count = 1 Then 'Was the value changed (Target) in range A1? If Not Intersect(Target, Range("A1")) Is Nothing Then 'Perform an action depending on Targets value. Select Case Target.Value Case 1 'Cut the Target cell (Ctrl+x). Target.Cut Case 2 'Copy the Target cell (Ctrl+c). Target.Copy Case 3 'Filldown from the Target 10 rows. Target.Resize(10).FillDown Case 4 'Change the font colour to red. Target.Font.Color = vbRed Case "Hello" 'Change the contents of the cell. 'This will cause the Change event to fire again, so disable events first. Application.EnableEvents = False Target.Value = "Goodbye" Application.EnableEvents = True Case Else 'If anything else is press keys Right Arrow, Up Arrow, F2. SendKeys "{RIGHT}{UP}{F2}" End Select End If End If End Sub