View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Worksheet_selectionchange Event

Possibly something like this: Selecting a cell will always fire the
event. You just design it to only do work when the correct cells are
selected.


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Fills exchange rate field based on currency selected
Dim x As Integer
If Target.Address < "$B$13" Then exit sub

On Error goto ErrHandler
Application.EnableEvents = False
If Range("e12") = "CDN" Then Range("b13").Value = _
Worksheets("data").Range("c2").Value
ElseIf Range("e12") = "USD" Then Range("b13").Value = _

End if

ErrHandler:
Application.EnableEvents = True
End Sub


--
Regards,
Tom Ogilvy


"Alex Mackenzie" wrote in message
...
I have code that I wish to have executed. It works fine, but it runs
regardless of what cell I have entered. I am using:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Fills exchange rate field based on currency selected
Dim x As Integer
If Target.Address = "$B$13" Then
If Range("e12") = "CDN" Then Range("b13").Value = _
Worksheets("data").Range("c2").Value
ElseIf Range("e12") = "USD" Then Range("b13").Value = _
etc.

Any advice would be greatly appreciated.

Thank you.