Yon*_*ong 2 excel vba excel-vba
H!我是VBA的新手.这可能是一个太简单的问题,但我正在努力使用VBA:当单击一个单元格(1,1),因为它有1,msgbox会显示"hi"
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
Run Code Online (Sandbox Code Playgroud)
此代码属于工作表模块.
右键单击工作表选项卡,然后选择"查看代码"
将此代码粘贴到那里:
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
Run Code Online (Sandbox Code Playgroud)