Consulting

Results 1 to 6 of 6

Thread: Delete row based on date and cell value

  1. #1
    VBAX Tutor
    Joined
    Jan 2006
    Posts
    248
    Location

    Delete row based on date and cell value

    I am wanting to delete rows that are greater than 30 days and based on the value "NO" in a cell. I have the date in column A and the Value "NO" will be in column C.

    I have this macro to delete rows greater than 30 days but I need to add to it that only rows with NO in them will be deleted.

    Sub DeleteCells()
    Dim LR As Long, I As Long
    Application.ScreenUpdating = False
    LR = Range("A" & Rows.Count).End(xlUp).Row
    For I = LR To 1 Step -1
        If Range("A" & I).Value <= Date - 30 Then Rows(I).Delete
    Next I
    Application.ScreenUpdating = True
    End Sub
    Thanks for any assistance

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    ...-30 And UCase(Range("C" & I)) = "NO" Then
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Tutor
    Joined
    Jan 2006
    Posts
    248
    Location
    Thanks SamT works perfect
    I will mark as solved
    Have a great New year

  4. #4
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    as an alternative, i regularly use autofilter method with large data sets.

    Sub vbax_54682_Del_Rows_Based_on_Two_Cols()
        With Worksheets("MySheet") 'change MySheet to suit
            .Cells(1).AutoFilter Field:=1, Criteria1:="<=" & (Date - 30)
            .Cells(1).AutoFilter Field:=3, Criteria1:="=NO"
            .UsedRange.Columns(1).Offset(1).SpecialCells(12).EntireRow.Delete
            .AutoFilterMode = False
        End With
    End Sub
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  5. #5
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Why are you invoking the Column Object?
    .UsedRange.Columns(1).Offset(1).SpecialCells(12).EntireRow.Delete
    SamT
    Fellow ID Follower
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  6. #6
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    you may assume i am too lazy to amend the adopted code if it produces the same result.
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •