You are here:

Excel/VBA To Return Most Recent date For A value

Advertisement


Question
TestFile
TestFile  
Hi Tom,
Thank you for assisting me in the past.

I use Excel 2007. Currently working on a large spreadsheet with several thousand rows and records of LPG tank records.

Attaching a simplified image with random data and dates(not actual).

Sample data Arrangement:
Column "A" - Serial Numbers, Column "B"- Inspection Date, Column "C"- External Inspection date, and  Column - "D" - Internal Inspection Date.

Each Serial number can have several inspection dates with external and internal dates next to it in the adjacent columns.

I need a vba that will for each unique value in column "A" return the max inspection date from Column "B" for that unique value, and the corresponding "Next External" from Column "C" and "Internal" Inspection Dates from Column "D".

Thank you,
Yogi

Answer
Yogi,

why not just add a column to the first sheet (with the data).  Assuming the data starts in A2 with a header in A1  (Assumes Excel 2007 or later)

E2:=if(countifs(A:A,A2,B:B,">"&B2)=0,"Yes","No")

Drag fill down the column E

Now filter on column E selecting "Yes"

copy to the master sheet.

That should give you what you want.

If you need code to do that, then just turn on the macro recorder while you do it manually.

--
Regards,
Tom Ogilvy

About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

Excel

All Answers


Answers by Expert:


Ask Experts

Volunteer


Tom Ogilvy

Expertise

Selected as an Excel MVP by Microsoft since 1999. Answering Excel questions in Allexperts since its inception in 2001. Able to answer questions on almost all aspects of Excel's internal capabilities. If seeking a VBA solution, please specify that in your question itself so I give you the answer you want. [Excel has weak protection - if you are distributing an application, I don't answer questions on how to protect your project from your users.]

Experience

Extensive experience.

Education/Credentials
Master of Science (MS) degree Operations Research (ORSA)

Awards and Honors
Microsoft MVP in Excel.

©2016 About.com. All rights reserved.