ranges

  • Thread starter Thread starter kevin carter
  • Start date Start date
K

kevin carter

hi
i have a worksheet which contains a lot of data
what i want to do is to select a cell, when this cell is active i want
to show the value of the cell in a comment box
i have this macro to start with (called from sheet code)

Sub macro1()
Dim rng As Range
Dim cell As Range
Set rng = ActiveSheet.Range("c1:c3")
For Each cell In rng
If cell.Value <> "" Then
MsgBox " here"
Exit For
End If
Next
End Sub
Problem i have with that code is the whole sheet is active ( i click any
cell on the worksheet and the message box pops up)
where am i going wrong?

thanks in advance

kev
 
Hi
try the following code in your worksheet module:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Intersect(Target, Me.Range("C1:C3")) Is Nothing Then Exit Sub
if target.value <>"" then
msgbox target.address & ": " & target.value
end if
End Sub
 
thanks Frank
works a treat
Frank Kabel said:
Hi
try the following code in your worksheet module:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Intersect(Target, Me.Range("C1:C3")) Is Nothing Then Exit Sub
if target.value <>"" then
msgbox target.address & ": " & target.value
end if
End Sub
 
Back
Top