+ Reply to Thread
Results 1 to 8 of 8

VBA Help - Loop to check/count against rows using date & time criteria

  1. #1
    Registered User
    Join Date
    06-02-2017
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    5

    VBA Help - Loop to check/count against rows using date & time criteria

    Hi,

    I'm trying to create a spreadsheet that has passed my level of expertise! Usually use recorded macro's and formulas but think this might be a VBA code job?

    I have attached a simplified version of my sheet to assist.

    On the data tab i have several columns of data. The only pertinent columns of data are the ones highlighted yellow (Name, ID, Date & time) however i have left in the other columns and populated the cells with "data" to reflect that there are several other columns in this sheet.

    In column T i have a cell called seconds (currently 15) which can/will be changed.

    My objective for this spreadsheet is to take each row of data (starting with row 2) and check it against all other rows in the sheet and count if my criteria is met. Once row 2 is done, continue for all rows.

    The criteria i need it to count against is as follows:

    - Name (col A) does NOT equal same name as the row being checked (therefore looking for different names)
    - ID of another row is the SAME as that being checked
    - Date and time of another row are within X seconds of the date and time of row being checked (X being the T2 cell - currently 15)

    Where the criteria is met i would like it to count as 1 and return the result on the results tab as a total count of a pair of names. I have manually inserted the counts for the sample data. So to clarify where John & Paul are paired together there are 3 instances where the ID is the same and the date and time are within 15 seconds of each other and at the other end of the scale there are 0 instances where George & Ringo have the same ID and are within 15 seconds of each other.

    Hope that makes sense! In summary i'm looking for some kind of code that will loop through and result each row until all rows are checked.

    Few things to be aware of:

    - The amount of rows that will be in the real spreadsheet are likely to run into the thousands
    - The amount of names are likely to run into the hundreds
    - There is no issue if any solution takes a while to process
    - T2 cell is a user defined time but realistically never going to look beyond 30 seconds
    - I need each row to check all rows and not just the ones below it. E.g when the loop hits row 3 i still need it to look at row 2 aswell as row 4 onwards

    If anyone is capable of providing code that i can attach to a button i would be eternally grateful!

    Many thanks in advance
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,945

    Re: VBA Help - Loop to check/count against rows using date & time criteria

    Use formulas - you need to create a list of unique names in the cells that are filled with green background, then expand the formulas used to match your list size.
    Attached Files Attached Files
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    06-02-2017
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    5

    Re: VBA Help - Loop to check/count against rows using date & time criteria

    Thanks for your time & help Bernie. I think this may be able to give me enough to work with and get a working solution going. One problem i face is that i could potentially have hundreds of uniques names in my data so generating a list of pairs on the results tab may be a challenge in itself but i'll give it a go!

    Thanks again, much appreciated

  4. #4
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: VBA Help - Loop to check/count against rows using date & time criteria

    Re: Generating a unique list of names. I don't think it makes a difference if you compare Paul to Ringo or Ringo to Paul. If Paul is within 15 seconds of Ringo twice, then Ringo has to be within 15 seconds of Paul twice. Am I interpreting this correctly?
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  5. #5
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,945

    Re: VBA Help - Loop to check/count against rows using date & time criteria

    When you have your list of unique names, to create the pairings, put the list onto a blank sheet starting in Cell A1 (don't use a header), and run this macro:

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    06-02-2017
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    5

    Re: VBA Help - Loop to check/count against rows using date & time criteria

    Yes that's correct dflak, I don't need to see each pair twice (despite my attachment appearing like that!). A list of unique pairs would do the job. Thanks

  7. #7
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,945

    Re: VBA Help - Loop to check/count against rows using date & time criteria

    Then use this code to create the unique pairs, for a list of names starting in A1:

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    06-02-2017
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    5

    Re: VBA Help - Loop to check/count against rows using date & time criteria

    Thanks Bernie, That works perfectly!

+ 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. Delete rows when criteria met in date and time
    By MicroTees in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-21-2015, 12:47 PM
  2. count the number of occurance based on time and date and specific criteria
    By stoey in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-02-2014, 03:34 PM
  3. [SOLVED] Macro to find the count of rows based on Date and Given Criteria.
    By raovv in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-15-2013, 02:48 AM
  4. [SOLVED] To count the number of rows based on date and check how old the row is from current date.
    By raovv in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-04-2013, 11:45 AM
  5. Count rows with multiple criteria incl max date
    By johnnyr1ngo in forum Excel General
    Replies: 3
    Last Post: 11-30-2010, 12:44 PM
  6. Replies: 0
    Last Post: 07-20-2010, 11:42 AM
  7. Replies: 0
    Last Post: 08-28-2005, 10:35 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