+ Reply to Thread
Results 1 to 11 of 11

Delete range of cells based on a cell value (Date).

  1. #1
    Forum Contributor pipoliveira's Avatar
    Join Date
    08-09-2012
    Location
    Ireland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    368

    Delete range of cells based on a cell value (Date).

    Dear all,

    I hope you are all well.

    I am looking for a VBA code that will delete a range of cells based on one of the cells value.

    I have attached a file into this thread.

    This is an Out-Of-Office table that is maintained by one person and that table has the following headers:

    Employee - From - To

    What I need is a VBA code that deletes the line that the date in column "To" is past (from today).

    Is that a way to do it? Maybe on the event "Worksheet_Calculate"?

    Your assistance on this matter will be highly appreciated.

    Best regards,
    Filipe Oliveira.
    Attached Files Attached Files

  2. #2
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Delete range of cells based on a cell value (Date).

    Hi Filipe,
    maybe so
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor pipoliveira's Avatar
    Join Date
    08-09-2012
    Location
    Ireland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    368

    Re: Delete range of cells based on a cell value (Date).

    Hi Nilem,

    Thank you for your example.

    Sorry for replying only now but I did replied to you before, maybe my reply did not went through for some reason.

    Your code did deleted the entry but it deletes the table row. What I need is to delete the values only, not the entire table row.

    If you test your code on the example I have attached, you can see that every time you change sheets, the code deletes a row from the Table, even with data or not.

    Any other recommendations on this matter will be highly appreciated.

    Best regards,
    Filipe

  4. #4
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Delete range of cells based on a cell value (Date).

    try using .ClearContents instead of .Delete

  5. #5
    Forum Contributor pipoliveira's Avatar
    Join Date
    08-09-2012
    Location
    Ireland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    368

    Re: Delete range of cells based on a cell value (Date).

    Thanks a million stnkynts,

    The answer I was looking for. I should have known better.

    Really appreciated by your help.

    Best regards,
    Filipe Oliveira.

  6. #6
    Forum Contributor
    Join Date
    08-11-2012
    Location
    bengalur
    MS-Off Ver
    Excel 2003, 2007
    Posts
    152

    Re: Delete range of cells based on a cell value (Date).

    Yes I feel that stnkynts is correct, instead of using .Delete use .ClearContents.

    _________________________________________________________________________________________________________________________________________
    Please click * if something has helped

  7. #7
    Forum Contributor pipoliveira's Avatar
    Join Date
    08-09-2012
    Location
    Ireland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    368

    Re: Delete range of cells based on a cell value (Date).

    Sorry guys, I have found an error on the code provided by nilem.

    The code works perfectly when there's dates on the past, but if there is a date that is still current or in the future, I receive the following error:
    "Run-time error '1004
    No cells found"

    I use this code under "Workbook_Activate".

    The other thing that happened was the code deleted everything under row D.

    Any suggestions will be highly appreciated.

    Best regards and thanks for your help in advance.

    Best regards,
    Filipe

  8. #8
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Delete range of cells based on a cell value (Date).

    Hi Filipe,
    I was not able to reproduce the error. Could you show an example of your data file where the error occurs.

  9. #9
    Forum Contributor pipoliveira's Avatar
    Join Date
    08-09-2012
    Location
    Ireland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    368

    Re: Delete range of cells based on a cell value (Date).

    Hi nilem,

    Once again, my reply, for some reason, did not came through. Sometimes this forum is not available or crashes.

    The problem with the code is that deletes all contents of the row.

    I have few series of tables within the same sheet. Running this code, it will not only delete the row from the required table, but it deletes all contents of the row (e.g. row 3).

    I have updated the file with other table beside it. Try to add a date in the past, change sheets and you will see that the contents of the other table (from same row) will be deleted as well.

    Resuming, I just want the contents inside the table "Out Of Office" to be deleted.

    Many thanks in advance and kind regards,
    Filipe
    Attached Files Attached Files

  10. #10
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Delete range of cells based on a cell value (Date).

    Hi Filipe,
    try
    Please Login or Register  to view this content.

  11. #11
    Forum Contributor pipoliveira's Avatar
    Join Date
    08-09-2012
    Location
    Ireland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    368

    Re: Delete range of cells based on a cell value (Date).

    Hi nilem,

    Thanks a million for your reply, it did worked on the example file I sent you.

    On my current file, this macro does not work and I believe for the fact that the table I have contains 3 columns as per the example, but each column have merged cells.

    I will try to sort somehow and find a code that will work as well with merged cells.

    Thanks a million for your assistance.

    Best regards,
    Filipe

+ 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. Macro Needed to delete range of cells based on null values in another cell
    By jeffmarsiglio in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-13-2013, 08:22 AM
  2. Formatting cells based on another cell date range
    By howie8790 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-26-2012, 01:53 PM
  3. Displaying in one cell a date range based on the dates of two different cells?
    By jonvanwyk in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-27-2011, 01:20 PM
  4. Sum a range of cells based on Date in another cell
    By BrandonNC in forum Excel General
    Replies: 1
    Last Post: 07-21-2010, 02:52 AM
  5. Delete Rows based on date range.
    By ge0rge in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-13-2009, 10:52 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