Excel2003,用VBA代码解决连续点击指定单元格,在指定单元格循环显示0-3的问题,非常感谢!

如题所述

EXECL worksheet事件里没有单元格单击事件,所以没有直接方式实现你的要求,毕竟你的要求里写着 不用点击其他单元格转换。以下有两种变通方式实现,看是否能帮到你。
第一种:不点击K17单元格,而是点击按钮。代码如下:
Private Sub CommandButton1_Click()

If Cells(17, 13) = 3 Then
Cells(17, 13) = 0
Else
Cells(17, 13) = Cells(17, 13) + 1
End If
End Sub
第二种:鼠标右键单击K17单元格(非左击),而是点击按钮。代码如下:
'单击右键方式
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
If Target.Row = 17 And Target.Column = 11 Then
Cancel = True
If Cells(17, 13) = 3 Then
Cells(17, 13) = 0
Else
Cells(17, 13) = Cells(17, 13) + 1
End If
End If
End Sub
温馨提示:答案为网友推荐,仅供参考