+ Reply to Thread
Results 1 to 9 of 9

Triggering code when leaving a cell.

  1. #1
    Registered User
    Join Date
    09-16-2012
    Location
    Portsmouth, England
    MS-Off Ver
    Excel 2003
    Posts
    11

    Triggering code when leaving a cell.

    Hello Everyone

    I'm in the process of writing an Excel program that helps to pick out horses that stand a good chance of winning a race. In one column I need to type in the amount the distance a horse lost its last race by( "0L" if it won) IE: "5L" if it lost by 5 lengths, "6Y" if it lost by 6 yards etc. Most of the time it will lose by n Lengths. It would save a considerable amount of time if I only needed to type the number and when moving to another cell the program automatically adds the "L" after the number and if the horse only lost by n yards then it wouldn't add the "L". Is it possible to trigger code when leaving a cell and if it is, how do I do it?

    Many thanks in advance.
    Jim

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Triggering code when leaving a cell.

    right-click the worksheet tab and select "view code" and then paste this code into the window that appears
    Please Login or Register  to view this content.
    adjusting the column to monitor as needed
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Registered User
    Join Date
    09-14-2012
    Location
    Philippines
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Triggering code when leaving a cell.

    Hi,

    How will excel know that the data you entered is "L" or "Y"?

    Rundie

  4. #4
    Registered User
    Join Date
    09-16-2012
    Location
    Portsmouth, England
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Triggering code when leaving a cell.

    Thanks very much for your help JP. It works a treat.

  5. #5
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Triggering code when leaving a cell.

    you're welcome :-) please remember to mark the thread solved to save the mods some time

  6. #6
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Triggering code when leaving a cell.

    JosephP

    Hi JP,

    Your Code baffles me a bit. It works fine until you delete a Range in Column A, and then all the Cells within that Range gets populated with a "L".

    I have tried to see how to "fix" this for you guys, but I seem stumped.

  7. #7
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Triggering code when leaving a cell.

    damn-looks like isnumeric is a little overzealous
    Please Login or Register  to view this content.

  8. #8
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Triggering code when leaving a cell.

    @ JosephP

    Cool ! That is how I got to know you and your effective Coding.

    I would never have thought of using the Len bit in there. Learnt something new today.

    Thanks!

  9. #9
    Registered User
    Join Date
    09-16-2012
    Location
    Portsmouth, England
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Triggering code when leaving a cell.

    Thanks again JP. was having the same problem but the above code fixed it.

+ 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