Dim
Dim

Reputation: 4807

Show value of specific cell in Excel macro

I am new to excel macro. What I need to to is by clicking on specific cell in A column I will know It`s value. Can you help me with this?

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

Upvotes: 0

Views: 1209

Answers (1)

Shai Rado
Shai Rado

Reputation: 33672

Use the code below to check the value of any cell in Column A once you click on it, this code should be added to your relevant Sheet to Worksheet_SelectionChange event :

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

Upvotes: 1

Related Questions