如何查找单击工作簿上特定单元格上的checkbox事件。

嗨,我有很多工作表,其中我有一个很多单元格列AI ,其中有checkbox。

我想要在该列A1上的该checkbox上单击一个事件处理程序。 我试过这个代码:

 Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Selection.Count = 1 Then If Not Intersect(Target, Range("AI")) Is Nothing Then MsgBox "Hello World" End If End If End Sub 

这个代码在点击不在checkbox上的单元格上工作。

如何查找点击checkbox? 还可以获取被点击的checkbox的行号。

提前致谢。

您必须将macros指定给checkbox。 下面的代码将运行,当您勾选macros指定的checkbox。

 Option Explicit Public Sub check_box_ticked() Dim cbox As Integer Dim wb As Workbook, ws As Worksheet, checkb as Shape Set wb = ThisWorkbook Set ws = wb.Sheets("Sheet1") Set checkb = ws.Shapes("Check Box 1") cbox = ws.CheckBoxes("Check Box 1").Value If cbox = 1 Then 'if message box is ticked then run code ' You can also use BottomRightCell MsgBox ("Row: " & checkb.TopLeftCell.Row & "Column: " & checkb.TopLeftCell.Column) End If End Sub 

当勾选checkbox时,这将返回列号和行号。