+ Reply to Thread
Results 1 to 4 of 4

How to delete a cell after a certain period of time?

  1. #1
    Registered User
    Join Date
    09-10-2021
    Location
    New Jersey
    MS-Off Ver
    2016
    Posts
    1

    How to delete a cell after a certain period of time?

    Hi everyone,

    I am looking to see if it is possible to write automate something I am doing at work. I am looking to have a code that deletes a cell's information after 6 months if the color of the text has been changed to red.

    Specifically, I have a list of phone extensions with names. If a name is changed to red, after 6 months, the name can be deleted rather than having to manually go in and see when it was changed to red from a comment posted by whoever changed the color.

    I am not exactly sure how to write it but this is what I have so far (found on another forum). I have 2 spreadsheets, one named Data with all the data and one named Time Log that has the date and time the cell was updated. Any advice would be great!! I don't have a lot of experience writing code but I am trying to learn more.




    Private Sub Worksheet_Activate()

    Dim stampcell As Range

    Dim TLSh As Worksheet


    Set TLSh = Worksheets("Time Log")


    Application.ScreenUpdating = False

    ''' Check if pass the 24h period to delete content

    For Each stampcell In TLSh.Range("B2:B1000")

    If Now > stampcell.Value2 + TimeValue("23:59:59") Then

    Me.Range(stampcell.Address).ClearContents

    stampcell.ClearContents

    End If

    Next stampcell

    Application.ScreenUpdating = True


    End Sub


    Private Sub Worksheet_Change(ByVal Target As Range)

    Dim myRng As Range

    Dim stampcell As Range

    Dim TLSh As Worksheet


    Application.EnableEvents = False


    Set TLSh = Worksheets("Time Log") ''' Time stamp sheet

    Set myRng = Range("B2:B1000") ''' Your targeted range



    If Not Intersect(Target, myRng) Is Nothing Then '''Time-stamping

    TLSh.Range(Target.Address).Value2 = Now

    TLSh.Range(Target.Address).NumberFormat = "MM/DD/YYYY hh:mm:ss"

    End If



    Application.EnableEvents = True


    End Sub
    Attached Images Attached Images

  2. #2
    Spammer
    Join Date
    10-23-2012
    Location
    Adelaide, Australia
    MS-Off Ver
    Excel 2003, Office 365
    Posts
    1,237

    Re: How to delete a cell after a certain period of time?

    Your code will log the date every time the cell in column B is changed. This means that every time time you change the spelling of a name or add a new name,
    the date will be logged and (I assume) when you check the date it will delete it after 6 months (your code has one day), which is not what you want.

    The other problem with doing it the way you suggested is that a font colour change does not generate an event per se which you can use to log the date.

    Doing something that actually changes the value of the cell and then checking if the change means delete this person in 6 months time, then log the date that change was made, would be the way to go.

    What you could do is;

    Have a drop down box with one selection "Delete". Use a SelectionChange event to remember the name and if Delete is selected restore the original name in red font then log the date?
    Attached Files Attached Files
    Last edited by Croweater; 09-10-2021 at 10:33 PM.

  3. #3
    Valued Forum Contributor unit285's Avatar
    Join Date
    10-29-2015
    Location
    TN
    MS-Off Ver
    Office 365
    Posts
    358

    Re: How to delete a cell after a certain period of time?

    Maybe something like this?
    Please Login or Register  to view this content.
    Attached Files Attached Files

  4. #4
    Spammer
    Join Date
    10-23-2012
    Location
    Adelaide, Australia
    MS-Off Ver
    Excel 2003, Office 365
    Posts
    1,237

    Re: How to delete a cell after a certain period of time?

    So, after breaking the golden rule of this forum by not using code tags (which the moderators MISSED by the way...tut tut), you now have had a few days (at least) to analyse the responses.

    Are you just going to cut and run or are you going to come back, tell us how great we are and give us LOADS and LOADS of rep points?

    Rep points are the currency here ya know and we all have families to feed! LOL.

+ 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. Auto delete cell info after fixed time period
    By ConfsuedRob in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 0
    Last Post: 06-23-2020, 05:49 AM
  2. [SOLVED] Formula/method to sort by specific time period within date+time ranges in cell
    By mikeskins84 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 02-13-2018, 01:12 PM
  3. [SOLVED] Calculate the portion of a planned number during a period, based on another time period
    By BryGuy81 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-19-2017, 01:29 PM
  4. Delete rows after a certain time period has passed
    By JRC1 in forum Excel Programming / VBA / Macros
    Replies: 26
    Last Post: 03-02-2017, 05:57 AM
  5. Replies: 0
    Last Post: 07-25-2013, 10:03 AM
  6. [SOLVED] Complicated:Calculate time period based on no. of units sold + fluctuations within period
    By omaha.crab in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-06-2012, 03:04 AM
  7. Variable time period/cell reference
    By richardeallen in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-01-2008, 12:05 AM

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