+ Reply to Thread
Results 1 to 2 of 2

Worksheet_selectionchange Event

  1. #1
    Alex Mackenzie
    Guest

    Worksheet_selectionchange Event

    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.



  2. #2
    Tom Ogilvy
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    > 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.
    >
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1