VBA点击一个单元格和动作,非常简单,但不适合我

H! 我是VBA新手。 这可能是一个太简单的问题,但我很努力地使用VBA:当单元格(1,1)被点击,因为它有1,msgbox会显示“嗨”

Sub test() 'click action 'when cell(1,1) is clicked and if cells(1,1) is 1, msgbox saying "hi" will show up, if not nothing If Cells(1, 1) = 1 Then MsgBox "hi" Else End If End Sub 

该代码属于工作表模块。

右键单击工作表选项卡并select“查看代码”

粘贴这个代码:

 Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Address = "$A$1" Then If Target = 1 Then MsgBox "hi" End If End If End Sub