+ Reply to Thread
Results 1 to 78 of 78

Compare dates and times and delete rows

  1. #1
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Compare dates and times and delete rows

    Hi all

    I have a spreadsheet that has 2 pieces of data - one of a actual date and time and the other latest date and time. I need to compare each record's time and keep the record that is closest between actual date and time and latest date and time. If the two match, then I need to keep the record that has the lowest value in Col G. I have attached a sample which hopefully explains.

    Is there a way I can achieve this in VBA?

    Thanks
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    I should have explained further:

    First I need to compare the time in Col E to the time in Col F for each record (each name in Col F is it's own record) and then find the times that are the closest match. I then need to keep that record and delete the others.

    Second, if the closest time match has more than one record (as shown in sample), I need to keep the record that has the lowest value in Col G.

    I am experimenting with comparing dates but I am having trouble with including records also.

    Can anyone please assist with this?

  3. #3
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    If anyone can please help me out, it would be really appreciated

  4. #4
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Compare dates and times and delete rows

    In your example you say rows 1 and 2 are the same so you need to keep the lowest col G value... but rows 4-6 seem to be a match as well for all other columns, so I don't understand the criteria for matching.

    Also, you say you want a comparison of time between columns E and F but the data in column F is not a time value.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  5. #5
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    ok I should have explained further.

    It is the time in Col E to compare to the time in Col H (not F).

    In rows 2 and 3 in the sample, the time in Col E is the closest match to the time in Col H for all records for item 1 (AT) which has 5 records (rows 2-6). So in this case I need to keep the row that has the lowest value in Col G (which is row 2).

    For the next record (item 2 - PN), the closest match in Col E to Col H is row 10 (it is an exact match), so I need to keep this row and delete the others.

    For the next record (item 3 - NZ), the closest match in Col E to Col H is row 14 (it is only 1 second difference), so I need to keep this row and delete the others.

    I hope this makes sense?

  6. #6
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,343

    Re: Compare dates and times and delete rows

    So there are fractions of a second (or maybe just fractions of a minute) difference in the times that are not visible at first glance right?
    If you want something done right... find a forum and ask an online expert.

    Time flies like an arrow. Fruit flies like a banana.

  7. #7
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    yes that is right. I have amended the format of the column of the columns now to be d/mm/yyyy h:mm:ss which shows the seconds difference (if any).

  8. #8
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    Does anyone know of a way I can solve this problem please?

  9. #9
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Compare dates and times and delete rows

    I'll have a go at this in a few minutes and reply here soon.

  10. #10
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Compare dates and times and delete rows

    Ok, how about this:

    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    this is perfect Arkadi, thanks!

    The only thing is, I have over 150,000 rows in my sheet and I need to run this frequently. Unfortunately it took over 15 mins

    Is there a way to speed it up?

    Also, some cells in Col E will be blank. In this case, I need to keep the row that has the lowest value in Col G. Can your code be adjusted to reflect this?

  12. #12
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    I wonder if it is possible to speed this macro up to account for my large worksheet??

  13. #13
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Compare dates and times and delete rows


    Hi !

    Yes like in that thread 'cause using SpecialCells and Delete is slow …

  14. #14
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Compare dates and times and delete rows

    Maym... Ill be looking at it today

  15. #15
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    great! Thank you so much Arkadi

  16. #16
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    Could anyone please assist me with this problem?

  17. #17
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Compare dates and times and delete rows

    maym, sorry, weekend got too busy with Mother's day stuff, but I'll try another approach soon...

  18. #18
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Compare dates and times and delete rows

    Give this one a try, should be faster...

    Please Login or Register  to view this content.

  19. #19
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    thank you Arkadi I ran it, it took 427 secs which is better than it was.

    Also, some cells in Col E will be blank. In this case I need to just keep the row (I had to delete them in order for your code to run). Is it possible to amend the code to account for this?

    Thanks

  20. #20
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    I am hoping there is someone who can assist me with this problem?

  21. #21
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Compare dates and times and delete rows

    Check this
    Please Login or Register  to view this content.

  22. #22
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    thank you jindon, that works great

    However, could the data appear on the same sheet (sheet 1)? At the moment it adds another sheet but I don't need this.

    Thanks

  23. #23
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    also, Col D sometimes has a value labelled "TBC". If this is the case, I need to keep all of these rows (and run the macro above on all the others). Is there a way the macro can be adjusted to achieve this?

    Thanks again.

  24. #24
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Compare dates and times and delete rows

    Change to
    Please Login or Register  to view this content.

  25. #25
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    thank you jindon. Could this code be adjusted to account for the values labelled "TBC" as outlined in my previous post?

  26. #26
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Compare dates and times and delete rows

    I didn't see that post...
    Please Login or Register  to view this content.

  27. #27
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    thank you jindon, that is great

    It is almost there. For those rows that have a value of "TBC" in Col D, I need to keep the row that has the largest value in Col H only. E.g. the values could be as follows:

    25/05/2016 3:45:02
    25/05/2016 3:45:12
    25/05/2016 3:45:01
    25/05/2016 3:45:07

    In this case I only need to keep the row with the 3:45:12 value as it is the largest.

    Can the code be adjusted to reflect this?

    Thanks again.

  28. #28
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Compare dates and times and delete rows

    Change to
    Please Login or Register  to view this content.

  29. #29
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    Thanks jindon, but it appears to be deleting all of the rows now with "TBC" in them?

  30. #30
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Compare dates and times and delete rows

    It leaves one line which have "TBC" in Col.D.

  31. #31
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    yes it has left one line in total, but it should leave one line for each record that has "TBC" in the value?

  32. #32
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    here is a sample so that you can see what is happening. It should delete each of the "TBC" rows but it only leaves one or two??
    Attached Files Attached Files

  33. #33
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    what I meant to say is that it should delete each record that isn't the largest value in Col H, so I have sorted the workbook and you will see for the first record, it should delete a number of rows and leave one, but it doesn't appear to be doing this?
    Attached Files Attached Files

  34. #34
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Compare dates and times and delete rows

    Quote Originally Posted by maym View Post
    thank you jindon, that is great

    It is almost there. For those rows that have a value of "TBC" in Col D, I need to keep the row that has the largest value in Col H only. E.g. the values could be as follows:

    25/05/2016 3:45:02
    25/05/2016 3:45:12
    25/05/2016 3:45:01
    25/05/2016 3:45:07

    In this case I only need to keep the row with the 3:45:12 value as it is the largest.

    Can the code be adjusted to reflect this?

    Thanks again.
    Can you explain the logic completely?
    This means when col.D is "TBC", it deletes all the rows but the largest in col.H?

  35. #35
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    yes that is correct. It will delete all the rows for each record, except for the largest in Col H. So in the attached sample, 1. Abo is one record. It should delete all the values except for row 7 (so rows 2 -6 and rows 8-24 to be deleted). 1. Bea is another record, so it should delete all the values except for row 27 (so rows 25-26 and row 28 to be deleted) and so on. I hope this makes sense?

  36. #36
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Compare dates and times and delete rows

    OK, I think the reference was wrong.
    Please Login or Register  to view this content.

  37. #37
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    I ran it on the sample sheet jindon and it deleted all but one record. So unfortunately it still is deleting too many records and not leaving the correct ones?

  38. #38
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Compare dates and times and delete rows

    That's why I asked.

    Quote Originally Posted by indon
    This means when col.D is "TBC", it deletes all the rows but the largest in col.H?

  39. #39
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    yes but if you see the sample sheet, you will see what I mean. The code deletes ALL ROWS, where it should only be deleting rows but leaving each record with the largest value. I have manually put the first few records in sheet 2 to show you what I mean.
    Attached Files Attached Files

  40. #40
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Compare dates and times and delete rows

    That means not ALL. Delete only non highest in same "se" col.F....
    Test this hard.
    Please Login or Register  to view this content.
    Last edited by jindon; 06-02-2017 at 03:51 AM.

  41. #41
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    thanks jindon, I wasn't explaining it correctly then. This looks great. I will check further tomorrow when I have some more time

  42. #42
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Compare dates and times and delete rows

    Just inform you that, I forgot to delete the msgbox lines for my testing use.

    If you have trouble, Hit Ctrl + Break to get into debug mode.

    Code has been edited.

  43. #43
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    thank you jindon, that works perfectly

    I almost have it, there is just one other piece that I am trying to solve for. This is a little different so I am not sure if I can post within this thread or if I need to start another.

    When the value is "TBC" in Col D, I need to check to see if the value in Col G is repeated, and if it is, I need to copy the value in Col D to that row. I have inputted these into a new Col (E) in the sample sheet to show you what I mean. This would be repeated all the way down, but I'm not sure how I could go about achieving this?
    Attached Files Attached Files

  44. #44
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    I should also add that in the sample sheet, the data appears in the very next row, but this may not always be the case with the real data.

  45. #45
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Compare dates and times and delete rows

    Like this?
    Please Login or Register  to view this content.

  46. #46
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    yes! That is great jindon, thank you!

    If I wanted to put the value in Col E (rather than replace the value in Col D) how can I adjust the code to do this?

  47. #47
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Compare dates and times and delete rows

    Change 2 lines
    Please Login or Register  to view this content.

  48. #48
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    perfect! Thank you so much!!

  49. #49
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Compare dates and times and delete rows

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  50. #50
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    I am trying to do the same thing on Col A but it is not working. I am using the following:

    Please Login or Register  to view this content.
    Can you please assist me with this?

  51. #51
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    Some rows are blank, and I am trying to put the value in Col A into them.

  52. #52
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    Quote Originally Posted by jindon View Post
    That means not ALL. Delete only non highest in same "se" col.F....
    Test this hard.
    Please Login or Register  to view this content.
    sorry to bring up an old thread, but I have an added complexity to solve for now with this.

    If there is no actual value in col E, i.e. column is blank, how can I amend the macro above to account for this? Everything works fine and has done so but now the report I receive can often leave this column blank. When it does, the macro completely removes all the data.

  53. #53
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Compare dates and times and delete rows

    Don't understand what you are trying to do from you code.

    Need to see your workbook with before/after.

  54. #54
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    ok I will explain further. In the attached workbook, I have shown what it looks like with example 1 before and after. This is how it currently works and it works fine. It compares times in Col E and ColF then takes the smallest value in Col G for the series.

    In example 2, I don't have times in Col E, so I have shown what it should look like in Example 2 After sheet.

    However the macro (when there is no data in Col E) gives me the 'type mismatch' error on this line:

    Please Login or Register  to view this content.
    Attached Files Attached Files

  55. #55
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Compare dates and times and delete rows

    So what is the logic to find the data to leave with col.E has no data?

  56. #56
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    well, when Col E has no data, the macro should find the latest date and time in Col H, keep this record and delete the others.

    The macro above will compare the dates and times between Col E and Col H and keep the lowest, but in the absence of no data in Col E, I don't think it works properly.

    I have updated the sample sheet to show what the correct output should be for example 2. If the latest date and time is the same for 2 records, it should keep the record with the lowest of the value in Col G (this is the case for the last 2 records).
    Attached Files Attached Files
    Last edited by maym; 10-01-2017 at 10:57 PM.

  57. #57
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Compare dates and times and delete rows

    I think I'm confused.

    Is this related to your original question?
    I mean should all the other conditions be taken in account?

  58. #58
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    yes, it is related as this was the original question (to compare the dates and times and keep only the rows that had the latest values) and the macro you provided me does this:

    Please Login or Register  to view this content.
    So now, keeping everything the same, if there is no values in Col E, I need to check for the latest value in Col H and keep these records. If the same date and time exists across more than one record, I need to keep the lowest value in Col G.

  59. #59
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    I believe it is to do with these lines:

    Please Login or Register  to view this content.
    As there is nothing in Col E, I am trying to amend the macro to say that there is no data in Col E so proceed with the rest but I just can't seem to get it?

  60. #60
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Compare dates and times and delete rows

    I think I understand the logic, but the result is different.
    Please Login or Register  to view this content.

  61. #61
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    thank you jindon. When you say the result is different, do you mean to the original solution you provided?

  62. #62
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Compare dates and times and delete rows

    No, different from your after sheet, I mean.

  63. #63
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    yours is actually capturing the correct data. In my after sheet. I did not have the latest values for some

  64. #64
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Compare dates and times and delete rows

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  65. #65
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    Hi

    I now get 'type mismatch' error on this line

    Please Login or Register  to view this content.

  66. #66
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Compare dates and times and delete rows

    No error and if you are testing with other data, no idea.

  67. #67
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    see attached sample taken from my 'real' data. The type mismatch error occurs here.

    Could you please take a look for me?

    The only thing I can think of is the date and time (perhaps because it is shown in a different format)?
    Attached Files Attached Files

  68. #68
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Compare dates and times and delete rows

    Col.H is just a text not date.

  69. #69
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    In this sample you mean? Or the other sample that I provided?

    Is there a way I can account for both formats in your code?

  70. #70
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Compare dates and times and delete rows

    If it is as date, should have no error.

    Col H in your latest file is not a date.

  71. #71
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    ok so if Col H is not a date but text, how can I adjust the code to account for both date and text?

  72. #72
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Compare dates and times and delete rows

    Why only text in this workbook?

    If it is mixed, almost impossible to read if it is a real date or not.

    dd/mm/yyyy or mm/dd/yyyy for data like 2/3/2017, 5/4/2017 etc.

  73. #73
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    also the macro outputs to a new sheet - is there a way it can overwrite the current data in sheet 1?

  74. #74
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Compare dates and times and delete rows

    replace "test" sub with
    Please Login or Register  to view this content.
    But what is the meaning of this, when the code doesn't work?

  75. #75
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    I get an error every time on this line:

    flg1 = w(1) < dif + ((w(1) = dif) * (w(2) > a(i, 7)))


  76. #76
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Compare dates and times and delete rows

    As I said, if Col.H is not date, no way, so please stop this.

  77. #77
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    sorry, wasn't clear enough. This is with date in Col H.

    Please see attached and you will see the error.
    Attached Files Attached Files

  78. #78
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Compare dates and times and delete rows

    I have just seen some of the dates are text. Sorry, will keep looking into it.

+ 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] Check dates, compare times and then delete rows
    By Estefanus in forum Excel General
    Replies: 3
    Last Post: 08-17-2016, 08:59 AM
  2. [SOLVED] Compare dates and times
    By tnubs in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-24-2014, 02:42 PM
  3. [SOLVED] Compare Dates/Times on Two Separate Sheets
    By dkcel in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 04-30-2013, 01:30 PM
  4. [SOLVED] Compare Dates and Times
    By saint01 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-15-2012, 04:48 PM
  5. macro to delete entire row of duplicate dates and times dd/mm/yyyy hh:mm:ss
    By bradyj2 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-02-2011, 05:41 AM
  6. Macro to compare multiple columns then delete rows with older dates
    By azurememories in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-23-2011, 05:43 PM
  7. delete rows containing old dates/times
    By mattmac in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-01-2009, 11:08 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