我是excel宏的新手。 我需要的是点击A栏中的特定单元格,我会知道它的价值。你能帮我解决这个问题吗?
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Selection.Count = 1 Then
If Not Intersect(Target, Range("D1:D200")) Is Nothing Then
MsgBox Range.("D" & Row_No).Value
End If
End If
End Sub
答案 0 :(得分:1)
使用下面的代码检查 A列中任何单元格的值,点击它后,此代码应添加到Worksheet_SelectionChange
事件的相关工作表中:
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim WatchRange As Range
Dim IntersectRange As Range
' setting Column A as watched Range
Set WatchRange = Range("A:A")
Set IntersectRange = Intersect(Target, WatchRange)
If Not IntersectRange Is Nothing Then
If Selection.Count = 1 Then
MsgBox Target.Value
Else
MsgBox "You have selected more than 1 cell !"
End If
End If
End Sub