+ Reply to Thread
Results 1 to 10 of 10

Automatically move and delete based on date

Hybrid View

  1. #1
    Registered User
    Join Date
    08-28-2020
    Location
    Germany
    MS-Off Ver
    Office 365
    Posts
    62

    Automatically move and delete based on date

    Hello,

    I have the following code that is moving candidates if I select "Yes" (move candidates) in "M:M".

    HTML Code: 

    Now I would like to integrate the following: As soon as I open the Excel it should check if the date in $D is older than today's date. If this is the case (to the contract ended), I want it automatically to move it to "Ehemalige Mitarbeiter" like in the example-code and delete the entire row afterwords out of the "Mitarbeiter"-sheet.

    How can I realize this?

    Thank you in advance.

  2. #2
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: Automatically move and delete based on date

    If this does not work upload a sample file please...

    Sub Auto_Open()
    With Sheets("Mitarbeiter").Cells(1).CurrentRegion
        .AutoFilter 4, "<" & CLng(Date)
        .Offset(1).SpecialCells(12).Copy Sheets("Ehemalige Mitarbeiter").Range("A" & Rows.Count).End(xlUp).Offset(1)
        .Offset(1).SpecialCells(12).EntireRow.Delete
        .AutoFilter
    End With
    End Sub
    Last edited by Sintek; 09-03-2020 at 07:30 AM.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  3. #3
    Registered User
    Join Date
    08-28-2020
    Location
    Germany
    MS-Off Ver
    Office 365
    Posts
    62

    Re: Automatically move and delete based on date

    Cheers,

    where to put it? Into the module or in the worksheet-code?

    Thank you in advance
    Last edited by Mievo; 09-03-2020 at 08:57 AM.

  4. #4
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: Automatically move and delete based on date

    Std Module...

  5. #5
    Registered User
    Join Date
    08-28-2020
    Location
    Germany
    MS-Off Ver
    Office 365
    Posts
    62

    Re: Automatically move and delete based on date

    It's not working 100%. I created an example file. Please note that the names are from a name generator, all info's are fictive. I added in red and bold what I want to achieve within the "Mitarbeiter"-worksheet, so it is easier for you probably.

    Thank you in advance for your help and effort, it is much appreciated!
    Attached Files Attached Files

  6. #6
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: Automatically move and delete based on date

    Why don't users ever start working in A1 on a worksheet?
    Sub Auto_Open()
    With Sheets("Mitarbeiter").Cells(5, 2).CurrentRegion
        .AutoFilter 3, "<" & CLng(Date)
        .Offset(1).Resize(.Rows.Count - 1).Columns("B:I").Copy Sheets("Ehemalige Mitarbeiter").Range("B" & Rows.Count).End(xlUp).Offset(1)
        .Offset(1).SpecialCells(12).EntireRow.Delete
        .AutoFilter
    End With
    End Sub
    Last edited by Sintek; 09-03-2020 at 10:29 AM.

  7. #7
    Registered User
    Join Date
    08-28-2020
    Location
    Germany
    MS-Off Ver
    Office 365
    Posts
    62

    Re: Automatically move and delete based on date

    Thank you. Could you test my sheet? I get "runtimeerror 13" (= original error: "Laufzeitfehler 13") when opening the Excel, but I think the error is in my worksheet-code I added to "Tabelle9 (Mitarbeiter)"..

    Edit: And your code moved all employees to the sheet, even though their contract didn't end yet. And it moved it into "A", but it must be moved from "B" on.
    Last edited by Mievo; 09-03-2020 at 03:31 PM.

  8. #8
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: Automatically move and delete based on date

    Upload file with expected result on sheet...because this is your requirement...

    As soon as I open the Excel it should check if the date in $D is older than today's date. If this is the case (to the contract ended), I want it automatically to move it to "Ehemalige Mitarbeiter" like in the example-code and delete the entire row afterwords out of the "Mitarbeiter"-sheet.
    even though their contract didn't end yet
    Does this not mean Vertragsende which is in Col E?

    Sub Auto_Open()
    With Sheets("Mitarbeiter")
        With .Range("B5:M" & .Cells(.Rows.Count, 2).End(xlUp).Row)
            .AutoFilter 4, "<" & CLng(Date)
            .Offset(1).SpecialCells(12).Copy Sheets("Ehemalige Mitarbeiter").Range("B" & Rows.Count).End(xlUp).Offset(1)
            .Offset(1).SpecialCells(12).EntireRow.Delete
            .AutoFilter
        End With
    End With
    End Sub

    And why oh why do you have 1,048,576 rows populated with data validation?
    Last edited by Sintek; 09-04-2020 at 01:58 AM.

  9. #9
    Registered User
    Join Date
    08-28-2020
    Location
    Germany
    MS-Off Ver
    Office 365
    Posts
    62

    Re: Automatically move and delete based on date

    Yes, you were right, it was E, not D. My bad, sorry.

    Here is the Excel sheet. It is not working 100%. It moves people, but 1. it doesn't set back the filter, so the data is still filtered and 2. (which is more important) it doesn't move every candidate. I have one candidate with April/2020 in there and she didn't get moved to the "Ehemalige Mitarbeiter" sheet, even though the contract ended months ago. Not sure why this is happening because it is moving other candidates aswell.

    Thanks for checking!
    Attached Files Attached Files

  10. #10
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: Automatically move and delete based on date

    This is the last time...
    Every upload you keep on changing...
    April only has 30 days that's why it is not copying and deleting...Your date 31/04.2020
    It is resetting the filter...
    Your dates are not actual dates...
    See sample it works...
    Attached Files Attached Files

+ 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] Automatically move a row in excel to a new worksheet when a date is entred
    By EKG in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-13-2017, 08:03 AM
  2. automatically move rows based on data
    By josh101287 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-27-2015, 07:10 PM
  3. how do I automatically move data from one page to another based on the date
    By tkincannon in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-22-2013, 05:33 PM
  4. Automatically move a row of data based on cell value
    By mmogharreban in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-16-2013, 02:37 PM
  5. How to automatically delete rows in Excel based in day of week and date?
    By pr0no in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-04-2012, 03:22 PM
  6. automatically move to next sheet based on given time
    By stoey in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-20-2011, 09:53 AM
  7. How to Move the Data Date line Automatically
    By anbinponnith in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-09-2010, 11:20 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