+ Reply to Thread
Results 1 to 6 of 6

Deleting all rows if they match Date in Column Cell

  1. #1
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    271

    Deleting all rows if they match Date in Column Cell

    I have a sample worksheet (and other alike worksheets with similar pattern of data) in a workbook, but row data could vary from 3 days to 15 days spanning across rows of 500 to 20000 to 50000 rows. Worksheet has just hard coded data and no formula.

    Row data could vary in each worksheet but key identifier would be Date in Column O (Column No. 15), Date format dd-mmm-yy and always sorted on date sequentially. Row 1 in each worksheet is Header, which should never be deleted / disturbed

    Based on date contained in Cell O2 (O1 acts like Column Header) , I want a macro which could read date always from Cell O2, filter on that date, and delete all rows based on that date, including Row 2 (O2) in fastest possibly manner. I was trying something with

    Please Login or Register  to view this content.
    Now how to pass date from cell O2 which is date in format dd-mmm-yy to some variable and filter on that column, and delete all rows where similar date appears in column O, including Row 2 (Cell O2). After deleting such rows, filter should be removed.

    I guess With …..Ranges End With, would slow down the process, as in some worksheet, rows could be as high upto more than 50000

    A Sample workbook containing row data upto 487 rows with 3 dates, 10-May-17, 11-May-17, and 12-May-17 is attached, and wish to delete all data having 10-May-17 (reading from Cell O2), including row 2, such that, Header in Row1 will remain intact, and data only for 11-May-17, and 12-May-17 will remain.

    Thanks
    Attached Files Attached Files
    Last edited by analystbank; 05-15-2017 at 01:33 AM.

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

    Re: Deleting all rows if they match Date in Column Cell

    Try
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    271

    Re: Deleting all rows if they match Date in Column Cell

    @thanks Sir, jindon. That was the fastest, i'd doubt that With ...End With it could slow down the procedure, but this was fastest, as desired.

    Just curious to know the logic, what is the relevance of .Parent.[s1:s2] in your code?

    Please Login or Register  to view this content.
    Are you comparing the initial date content of O2 here, I use F8 to see, what exactly it does . Thanks, my query resolved. Thanks a lot.
    Last edited by analystbank; 05-15-2017 at 01:58 AM.

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

    Re: Deleting all rows if they match Date in Column Cell

    Quote Originally Posted by analystbank View Post
    @thanks Sir, jindon. That was the fastest, i'd doubt that With ...End With it could slow down the procedure
    Who told you so? It is only referencing to Range object, so it should not affect the speed.
    Quote Originally Posted by analystbank View Post
    Just curious to know the logic, what is the relevance of .Parent.[s1:s2] in your code?

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Becuase it is referring to the Range, Parent is Sheet("data") in this case.
    It is the same with/without the Parent keywords in this case due to the first cell is A1, however, if the range location differs, it needs to add that key word.

  5. #5
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    271

    Re: Deleting all rows if they match Date in Column Cell

    Thank you for all clarity.

    I'd read somewhere that Autofilter of data and performing task like deleting multiple range/row/column works faster than End...End With as the later has looping. Nevertheless, lesson learned is that there could not be generalised answer as it may vary from case to case, or possibly, your code is also making use of AutoFilter , so it is part of that.

    I'm not technically expert, so pardon me for less knowledge, trust, no offence for sharing my limited understanding. This thread is complete.

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

    Re: Deleting all rows if they match Date in Column Cell

    By the way, it is not AutoFilter, but AdvancedFilter was used.

+ 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] Hide rows in a worksheet if dates in two date column match - Macro
    By shailew in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-27-2013, 01:04 PM
  2. Deleting Rows of Data that does not match certain column's description
    By exlgh91 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 05-14-2013, 12:27 PM
  3. [SOLVED] Deleting part of a column without deleting whole rows.
    By dstrdOne in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-30-2013, 11:42 AM
  4. Deleting all rows where one column cell is less than 1
    By Graham Taylor in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-02-2012, 07:12 PM
  5. [SOLVED] Deleting a row where a cell contains a date in a column
    By macrohelp5 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-06-2012, 09:44 AM
  6. Replies: 1
    Last Post: 12-19-2011, 01:09 AM
  7. Replies: 3
    Last Post: 01-11-2006, 03:15 PM

Tags for this Thread

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