Rajvagadia
New Member
- Joined
- Aug 16, 2016
- Messages
- 3
Hello Team,
Need your help in deleting rows which are older than current month. I have written below Macro and I am able to delete data which are prior to 30 days old. Please advise how to write Macro for the data which will delete all old data except current month. Thank you.
Sub DeleteOlder()
Dim rng As Range
Dim cel As Range
Dim m As Long
B = Range("B" & Rows.Count).End(xlUp).Row
For Each cel In Range("B1:B" & B)
If cel.Value < Date - 30 Then
If rng Is Nothing Then
Set rng = cel
Else
Set rng = Union(rng, cel)
End If
End If
Next cel
If Not rng Is Nothing Then
rng.EntireRow.Delete
End If
End Sub
Need your help in deleting rows which are older than current month. I have written below Macro and I am able to delete data which are prior to 30 days old. Please advise how to write Macro for the data which will delete all old data except current month. Thank you.
Sub DeleteOlder()
Dim rng As Range
Dim cel As Range
Dim m As Long
B = Range("B" & Rows.Count).End(xlUp).Row
For Each cel In Range("B1:B" & B)
If cel.Value < Date - 30 Then
If rng Is Nothing Then
Set rng = cel
Else
Set rng = Union(rng, cel)
End If
End If
Next cel
If Not rng Is Nothing Then
rng.EntireRow.Delete
End If
End Sub