Results 1 to 3 of 3

Delete if older than 3 months and offsetting a cell input if match found

Threaded View

  1. #1
    Forum Contributor
    Join Date
    08-10-2014
    Location
    Alberta
    MS-Off Ver
    2016
    Posts
    128

    Delete if older than 3 months and offsetting a cell input if match found

    Hello, I have two questions, but they pertain to the same page. The rules do not state you cannot ask two questions, but I can see how that may be confusing, so perhaps it should be added(?).

    The first one is to delete a row of cells to the left if one column has an older date than today. The cell "P1" has =Today() in it, but it does not seem to work. What do I have incorrect? Here is the code:
        With Sheet8 'Delete older than 3 month cells in overnights
            Set rng = Range("G2:G99")
            For Each Cell In rng
                If Cell < Cells(1, "P") Then
                    Cell.ClearContents
                    Cell.Offset(0, -1).ClearContents
                    Cell.Offset(0, -2).ClearContents
                    Cell.Offset(0, -3).ClearContents
                    Cell.Offset(0, -4).ClearContents
                    Cell.Offset(0, -5).ClearContents
                    Cell.Offset(0, -6).ClearContents
                End If
            Next Cell
        End With
    The second issue is with offsetting a cell if the name is found in column 1. I have no idea on how to do this without entering it on a userform first. The difficult part is that it is on two different pages. So if another cell that is in Cell.Row, 2 has O/N in the row in ws1 and has the same name in ws2 already, then I want it to go into the next column, which is 3. This needs to be done until it gets to column 6. These cells in the new columns need to have DateAdd("d", -1, Date) in them. Here is the code I already have.

        With ThisWorkbook 'Overnight checklist copying
            Set ws1 = .Sheets("Guest Management")
            Set ws2 = .Sheets("Overnight Checklist")
        End With
            Set CheckRange = ws1.Range("G6:G38")
            For Each Cell In CheckRange
                If Cell.Value = "O/N" Then
                    
                    emptyRow = ws2.Cells(Rows.Count, "A").End(xlUp).Row + 1
    
                    ws2.Cells(emptyRow, 1) = Cells(Cell.Row, 2).Value
                    ws2.Cells(emptyRow, 2) = DateAdd("d", -1, Date)
                    ws2.Cells(emptyRow, 7) = DateAdd("d", 90, Date)
                End If
            Next Cell
    Here is what it looks like:
    Untitled.jpg
    With the dates being offset for Bob if there is another O/N.
    Last edited by Templemind; 09-27-2014 at 02:46 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Match Cell Content and Delete Cell Content If a Match is Found
    By aviatecar in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-30-2013, 01:29 PM
  2. [SOLVED] Match one cell with another, if match found copy adjacent cells
    By Xiophoid in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-07-2013, 05:50 AM
  3. Replies: 6
    Last Post: 05-24-2012, 09:14 AM
  4. Compare two sheets and delete row if match found
    By Steinwall in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-13-2011, 03:25 PM
  5. Regression - Having trouble offsetting input/output references
    By emadden in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 06-15-2009, 04:38 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