+ Reply to Thread
Results 1 to 15 of 15

Formula or Macro to return a value if cells match

  1. #1
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Formula or Macro to return a value if cells match

    Hello,

    I'm not sure is this is best done via macro or formula. Either way I have not idea how to write either one. I tries a vlookup but did not come close to what I wanted.

    I would to take a table of data and if 3 cells in a Row match 3 other cells in a different Row, the return value would be the difference of different cells in the two rows that match.

    I attached an example of what I would like the return value to be with another explanation.

    I would be very grateful for anyone willing to take a look at this for me.

    Thank you,

    -Justair
    Attached Files Attached Files

  2. #2
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Formula or Macro to return a value if cells match

    Try this, open workbook, enable macros, and click on the button.
    Attached Files Attached Files

  3. #3
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Re: Formula or Macro to return a value if cells match

    That worked perfect but I just realized that I was asking the question wrong. My data has a slightly different criteria that needs to be identified.

    I have cell's titled "Orders", "Footage", "Status". If the status says "Complete" then I need to find the status that says "Pending", and only if the "Footage" and "Orders" match does it return the difference in time.

    Attached is an edited sample. Sorry for the confusion.
    Attached Files Attached Files

  4. #4
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Formula or Macro to return a value if cells match

    Ok, try this.
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Re: Formula or Macro to return a value if cells match

    That's awesome! Do you know why the return is not showing the full difference from the dates? It's only showing the difference from the hours, it's excluding the days.

  6. #6
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Re: Formula or Macro to return a value if cells match

    That's awesome! Do you know why the return is not showing the full difference from the dates? It's only showing the difference from the hours, it's excluding the days.

  7. #7
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Re: Formula or Macro to return a value if cells match

    Hi millz,

    I'm having an issue with the code. For some reason it is only working if I have the "Completed" cell above the "Pending". Otherwise it doesn't work?

    Any ideas?

  8. #8
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Re: Formula or Macro to return a value if cells match

    Is it possible to switch the code so that way the difference is reversed?

    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Re: Formula or Macro to return a value if cells match

    Please Login or Register  to view this content.
    this worked

  10. #10
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Formula or Macro to return a value if cells match

    Quote Originally Posted by Justair07 View Post
    Hi millz,

    I'm having an issue with the code. For some reason it is only working if I have the "Completed" cell above the "Pending". Otherwise it doesn't work?

    Any ideas?
    Seems like you marked this as solved already. Because initially you only wanted to look for same "status" as per your requirements stated in the first post, then I changed it slightly to look for "Completed" first, then look for "Pending" below that row. If this is an issue still needs to be fixed, let me know again.

  11. #11
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Re: Formula or Macro to return a value if cells match

    Quote Originally Posted by millz View Post
    Seems like you marked this as solved already. Because initially you only wanted to look for same "status" as per your requirements stated in the first post, then I changed it slightly to look for "Completed" first, then look for "Pending" below that row. If this is an issue still needs to be fixed, let me know again.
    I worked around the issue, it still only works if "Completed" is above "Pending" but I just ran an ascending filter to make all "Completed" always be placed above "Pending".

  12. #12
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Re: Formula or Macro to return a value if cells match

    Hi millz,

    Do you know if there is a way to speed up the code. Maybe a different method perhaps? I tried
    Please Login or Register  to view this content.
    but is didn't seem to speed anything up.

    I currently have the code running through 35,000 lines of data and it take a long time.

    Just thought I'd ask and see if you had any ideas.

    As always, thanks for the help

  13. #13
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Re: Formula or Macro to return a value if cells match

    Hi millz,

    Do you know if there is a way to speed up the code. Maybe a different method perhaps? I tried
    Please Login or Register  to view this content.
    but is didn't seem to speed anything up.

    I currently have the code running through 35,000 lines of data and it takes a long time.

    Just thought I'd ask and see if you had any ideas.

    As always, thanks for the help

  14. #14
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Formula or Macro to return a value if cells match

    Since the code loops through a range, for that matter 35k, it tends to be very slow. I do not think adding screen updating will make much difference. Loading the data in to an array is the way forward.
    I understood your first request, i.e. matching 2-3 columns, but lost in your request in #3 as you have added some conditions on column A.
    Last edited by AB33; 09-20-2013 at 11:20 AM.

  15. #15
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Re: Formula or Macro to return a value if cells match

    AB33,

    Thanks for the reply,

    Basically, I have to be able to find cells that all meet certain conditions. For example: If the Cell titled "Status" says "Complete" and the adjacent cell titled "Footage" is the same value as a different row in the "Status" column with the label "Pending" and the "Footage" value is equal to the footage value of the "Complete" row, the time from the "Pending" cell will be subtracted from the "Complete" cell.

    I'm sorry if what i said made no sense it was the best way i could think to describe what i'm trying to accomplish.

    Thanks for the assistance.
    Last edited by Justair07; 09-20-2013 at 12:54 PM. Reason: typo

+ 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. Replies: 9
    Last Post: 07-22-2015, 03:32 PM
  2. Replies: 2
    Last Post: 11-12-2012, 06:26 AM
  3. Replies: 4
    Last Post: 09-06-2005, 06:05 AM
  4. Replies: 0
    Last Post: 09-06-2005, 03:05 AM
  5. Replies: 0
    Last Post: 09-06-2005, 02:05 AM

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