• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA in Excel for Mac - Delete rows outside dates

RosscoeMac

New Member
I am having some issues writing code for this:

I want to delete entire rows where the dates are outside two dates - that are contained in either two cells, or can be entered into an InputBox.

Any help would be appreciated as I'm old and stupid.

Thanks,

RosscoeMac
 
Here is the code I use which deletes rows not dated in August 2014. What I would like is the date range to be defined and referenced in two cells above a header row (or perhaps in an InputBox):

Sub ProcessData()





Dim Lastrow As Long

Dim i As Long



With ActiveSheet



Lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row

For i = Lastrow To 2 Step -1



If Year(.Cells(i, "A").Value) = 2014 And (Month(.Cells(i, "A").Value) = 8 Or Month(.Cells(i, "A").Value) = A) Then



'do nothing

Else



.Rows(i).Delete

End If

Next i

End With

End Sub
 
Back
Top