Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address(False, False) = "A10" Then
MsgBox "You can't go there!!"
Range("A1").Select
End If
End Sub
Here's an example which goes in a sheet's code module (right click the tab > View code)
Code:Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Address(False, False) = "A10" Then MsgBox "You can't go there!!" Range("A1").Select End If End Sub
If Target.Address = "$A$1" Then
If Target.Addres <> "$A$1" Then Exit Sub
MsgBox "Value of " & Target.Address & " is " & Target.Value
Here's an example which goes in a sheet's code module (right click the tab > View code)
Code:Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Address(False, False) = "A10" Then MsgBox "You can't go there!!" Range("A1").Select End If End Sub
Hi Shamas!
The address property simply identifies the location of the Target. Note that Target may be more than 1 cell.
You can use it to isolate a cell for macro execution. Example
orCode:If Target.Address = "$A$1" Then
You can use this property in a messageboxCode:If Target.Addres <> "$A$1" Then Exit Sub
Code:MsgBox "Value of " & Target.Address & " is " & Target.Value
Note that Target.Address is ALWAYS an absolute reference and in Caps.
So Target.Address ="A1" or Target.Address = "$a$1" will not work
lenze
Edit: Vog's code should go in the WorkSheet module, not the ThisWorkBook module