+ Reply to Thread
Results 1 to 4 of 4

Deleting rows based on Date and Text

  1. #1
    Registered User
    Join Date
    04-16-2013
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    2

    Deleting rows based on Date and Text

    Hello all, I am fairly new to macroing in excel and have been wrestling with a task I'd like to do via a macro. I need to delete rows based on the text in column A being either "1" or "2" AND the date in column B being farther out than 30 days from today. Either that, or the only other text that appears in column A is "3A", "3B", or "3C" so I could delete rows where column B contains a date greater than 30 days from now and column A does NOT contain 3A, 3B, or 3C... Any suggestions?

    Also, I am new to this forum so if there is anything else you need, please let me know. Note that I cannot attach the entire report, though I could likely compose a smaller mock report that does not contain certain irrelevant personal info if it is necessary

  2. #2
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,784

    Re: Deleting rows based on Date and Text

    Perhaps a macro like this would work for you?

    Please Login or Register  to view this content.
    Alf

  3. #3
    Registered User
    Join Date
    04-16-2013
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Deleting rows based on Date and Text

    Gracias. I greatly appreciate the help. Had to tweak just a bit, but without that jumping off point, not sure I'd have gotten it. So again, thank you.
    Final code worked out to be this:

    Dim LastRw As Long
    Dim i As Long

    LastRw = Range("A" & Rows.Count).End(xlUp).Row

    For i = LastRw To 1 Step -1

    If Cells(i, 1) = 1 And Cells(i, 2) > Now() - 365 + 30 Then
    Rows(i).EntireRow.Delete
    End If
    If Cells(i, 1) = 2 And Cells(i, 2) > Now() - 365 + 30 Then
    Rows(i).EntireRow.Delete
    End If
    Next


    Works like a charm

  4. #4
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,784

    Re: Deleting rows based on Date and Text

    Glad to be of help and thanks for feed back!

    Alf

    Ps Since you problem seems to be solved could you please mark your thread "Solved"

    To mark your thread solved do the following:
    - Go to the first post
    - Click edit
    - Click Advance
    - Just below the word "Title:" you will see a dropdown with the word No prefix.
    - Change to Solve
    - Click Save

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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