+ Reply to Thread
Results 1 to 9 of 9

VBA Code that will return max date based on multiple criteria

  1. #1
    Registered User
    Join Date
    08-14-2013
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    4

    VBA Code that will return max date based on multiple criteria

    Hello, I have been trying to create some efficiencies in my files using vba and macro's and i am currently in holding pattern. I have a number of columns that all contain different types of data (one column is names, others dates,..etc. However, in column C, i have 3 distinct values (CTR, BTW, and ATY) only. In column E, I have dates with times. I am trying to write a formula/macro that will provide me with the maximum date for (CTR) and the maximum date for (BTW & ATY); the date may change based on the date that the download occurs. I have tried to use the formula max and I have even tried to index the data. However, the answer is always coming back with the max date for the entire row. Plus, to add a complication, the range is variable and depends on the amount of data so its never a fixed range. I really hope someone can help. Thank you in advance for any thoughts on this.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA Code that will return max date based on multiple criteria

    Can you post a sample file? (Go to advanced and click on the paper clip.)
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    08-14-2013
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: VBA Code that will return max date based on multiple criteria

    Hello. Thank you for the quick reply. I am attaching the file. I have simplied the number of columns but the reasoning still holds. I hope this helps.
    Attached Files Attached Files

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA Code that will return max date based on multiple criteria

    I'll take a look tomorrow.

  5. #5
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA Code that will return max date based on multiple criteria

    Hi dubuquer,

    Here's a start - see if it's what you wanted:

    Please Login or Register  to view this content.
    Directions for running the routine(s) just supplied

    Copy the code to the clipboard

    Press ALT + F11 to open the Visual Basic Editor.

    Open a macro-enabled Workbook or save your Workbook As Macro-Enabled

    Select “Module” from the Insert menu

    Type "Option Explicit" then paste the code under it

    And, you should be ready to go

    With the cursor between Sub and End Sub press F5 (F8 to Single Step)

    OR

    Press ALT + Q to close the code window.

    Press ALT + F8 then double click on the macro name
    Last edited by xladept; 08-15-2013 at 07:49 PM.

  6. #6
    Registered User
    Join Date
    08-14-2013
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: VBA Code that will return max date based on multiple criteria

    Hello, Good evening. The code worked like charm (much appreciated). Is there a way to restrict the max date for BTW and ATY? What I mean is that I have only two types of data categories 1) The max date for CTR 2) The max date for BTW & ATY. I have a tab for 'time' that shows the end result I am hoping to achieve (new attachement with added tab). I could manipulate the results on the data tab to get there but I would imagine there is a much easier way of doing this with code. By running the code you provided, I would like to copy the final max data in a specific cell for the max of CTR and a specific cell for the max of BTW/ATY (the cells location will not change). Ultimately, I would like to reference that specific cell with the data in as a basis for a vlookup later. I hope this makes sense. Please let me know. Once again. This has been extremely helpful.
    Attached Files Attached Files

  7. #7
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA Code that will return max date based on multiple criteria

    Hi Dubuquer,

    It's a little sloppy but it seems to do what you want:

    Please Login or Register  to view this content.
    Last edited by xladept; 08-16-2013 at 06:58 PM.

  8. #8
    Registered User
    Join Date
    08-14-2013
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: VBA Code that will return max date based on multiple criteria

    Fantastic! This is exactly what I what looking for. Thank you again for the help.

  9. #9
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA Code that will return max date based on multiple criteria

    You're welcome!

+ 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. [SOLVED] How to return multiple values to a single cell based on multiple criteria
    By lwallace in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-20-2014, 06:32 AM
  2. Replies: 10
    Last Post: 02-19-2013, 12:05 PM
  3. Excel 2007 : Return Value Based on Multiple Criteria
    By pmhxcel in forum Excel General
    Replies: 12
    Last Post: 04-20-2011, 10:13 AM
  4. [SOLVED] Return a value based on multiple criteria
    By jacarutu in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-18-2010, 05:52 PM
  5. Count Multiple Entries, Return Multiple Rows, Based On 3 Criteria
    By gtj_global in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 09-20-2008, 06:40 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