+ Reply to Thread
Results 1 to 8 of 8

VBA: Create unique list based on latest entry in list

  1. #1
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    VBA: Create unique list based on latest entry in list

    I have a sheet which has 3 cols of data. Lotid, Yield(Yld), Test_date.

    For any given "date" I only have a single lotid. HOwever, i want to generate a list of
    lot-ids and their yield with the latest test date.

    See enclosed file......i try to show an example.

    I am trying to do this in VBA........

  2. #2
    Valued Forum Contributor Miraun's Avatar
    Join Date
    04-03-2009
    Location
    New England
    MS-Off Ver
    2003, 2007, 2010, 2013
    Posts
    554

    Re: VBA: Create unique list based on latest entry in list

    Given the conditions you provided, I was able to create it without VBA...

    Used two array formulae,
    {=SUM(IF(F3=$A$3:$A$15,IF(H3=$C$3:$C$15,$B$3:$B$15,0),0))} for the Yld,
    {=MAX(IF($A$3:$A$15=F3,$C$3:$C$15,0))} for the Test_Date...

    I assume the actual data is much larger than this, you can always do an advanced filter:
    Alt, D, F, A
    Then unique records only, copy to another location: F3
    Then copy the formulae down..

    Was there any particular reason you were looking for the output to be created in VBA?
    Attached Files Attached Files
    Going for Guru! Click the Star to the bottom left of this post if I helped!

  3. #3
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: VBA: Create unique list based on latest entry in list

    welchs101,

    Here's a macro solution. I have attached a modified version of your sample file so you can see how it works.
    Please Login or Register  to view this content.


    Hope this helps,
    ~tigeravatar

  4. #4
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Re: VBA: Create unique list based on latest entry in list

    thanks, both instances (in vba and out) are helpful. thanks.

    I was wanting to do this in vba as i am reading the file in via vba and i wanted to keep all the "work" in vba but its nice to know i can do this outside vba as well. So thanks.

    fyi: when i click on the get data button the macro has some issues running but if i go into the code and run it from there it works..........as i was hoping it would so thanks!!!!!!!!!!

  5. #5
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Re: VBA: Create unique list based on latest entry in list

    Every time i someone posts their soln i learn ALOT! Not only do i learn how to do what i was asking about but i learn different ways to do things. So thanks.

  6. #6
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Re: VBA: Create unique list based on latest entry in list

    As i am going through the code i am realizing that it works great. However, for my situation it may not. When i created the test file for the "excel forum" only put 3 of the cols of data. In fact there are about 30 cols of data in addition to the 3 i showed. For the code to work i would need to create an array for each col.

    What i was wondering is instead of using the arrays as they are in the code if some how we could just delete the row which has the lesser date. Does this make sense? Any ideas?

    Note: I really like the code. Took me a while to go through it. I have some other questions abou the previously posted code which i will start another thread for.....really cool!

  7. #7
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: VBA: Create unique list based on latest entry in list

    welchs101,

    I updated the code to only use two arrays. The beginning data only needs the start column, end column, and date column:
    Please Login or Register  to view this content.


    Hope this helps,
    ~tigeravatar

  8. #8
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Re: VBA: Create unique list based on latest entry in list

    thanks i will check it out.

+ 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