+ Reply to Thread
Results 1 to 7 of 7

VBA code to lookup previous failure date

  1. #1
    Registered User
    Join Date
    01-06-2015
    Location
    Dubai
    MS-Off Ver
    2010
    Posts
    4

    VBA code to lookup previous failure date

    Excel Help.jpg

    If I enter a Pump Number (016PC234B) in cell A9, I need the code to enter today's date in cell B9. Then it should lookup the last time this pump has failed (02-Feb-14) and enter it into cell C9. The last step is to calculate the time between the date in cell B9 and C9 and express it in terms of months. The calculation I use is [(B9-C9)/(365.25/12)]

    Thanks for helping me on this

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA code to lookup previous failure date

    Welcome to the Forum. You'll find you will get a lot more responses if you provide a spreadsheet with the sample data versus a picture. Try:

    Please Login or Register  to view this content.
    Last edited by JOHN H. DAVIS; 09-17-2015 at 10:24 AM.

  3. #3
    Registered User
    Join Date
    01-06-2015
    Location
    Dubai
    MS-Off Ver
    2010
    Posts
    4

    Re: VBA code to lookup previous failure date

    I tried the code but when I enter nothing happens. I also tried to attached the Excel spreadsheet but cannot find a way to do so.

    Obviously I am doing something wrong

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA code to lookup previous failure date

    Review this Forum Rules link under You Want To Get Your Questions Answered Quickly for instructions on how to attach a workbook.

    http://www.excelforum.com/forum-rule...rum-rules.html

  5. #5
    Registered User
    Join Date
    01-06-2015
    Location
    Dubai
    MS-Off Ver
    2010
    Posts
    4

    Re: VBA code to lookup previous failure date

    Thanks for the advise. I have attached the workbook.
    Attached Files Attached Files

  6. #6
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: VBA code to lookup previous failure date

    I tried the code but when I enter nothing happens.
    Alt + F8 to bring up the macro list, then run the macro named Brits.
    You can also highlight the macro name and choose options and set a shortcut key to run the macro.

    In your sample workbook P1613 is in cell A425, when I run the code I get today's date in B425 and February 27, 2014 in C425 as the previous failure date.
    Click the * Add Reputation button in the lower left hand corner of this post to say thanks.

    Don't forget to mark this thread SOLVED by going to the "Thread Tools" drop down list above your first post and choosing solved.

  7. #7
    Registered User
    Join Date
    01-06-2015
    Location
    Dubai
    MS-Off Ver
    2010
    Posts
    4

    Re: VBA code to lookup previous failure date

    This works perfectly thank you.

    Would it be possible to do the same, but not using the macro. When you press enter after entering the tag number it executes the code?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. VbA code to find previous date
    By aman1234 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-25-2015, 09:32 AM
  2. Replies: 0
    Last Post: 02-25-2015, 01:02 PM
  3. [SOLVED] vba code to open excel file name in previous weekday date
    By prabhuduraraj09 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-23-2014, 05:09 PM
  4. VBA code-Signature code failure
    By khaledocom in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-09-2011, 12:13 PM
  5. code failure
    By dreamz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-07-2006, 03:42 PM
  6. [SOLVED] VBA Code Reference to Solver Failure !
    By monir in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-29-2006, 11:55 PM
  7. Chart versus Work Sheet Code Failure
    By Nigel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-18-2005, 01:06 PM

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