kelly mort
Well-known Member
- Joined
- Apr 10, 2017
- Messages
- 2,169
- Office Version
- 2016
- Platform
- Windows
This code deletes the entire row. Now I want to clear just data from a given range intead. I want to clear data from T4:X & LastusedRow. V contains the dates. I have been trying to fix it but seems hard to read and understand it. Actually the dates are sorted in descending order.
Code:
Sub DeleteRows()
Dim c As Range, DeleteRange As Range, DataRange As Range
Dim LR As Long
'change sheet name as required
With Worksheets("[COLOR=#ff0000]Sheet1[/COLOR]")
'find last row in range
LR = .Cells(.Rows.Count, "B").End(xlUp).Row
'range you are searching
Set DataRange = .Range("B1:B" & LR)
End With
DataRange.EntireRow.Hidden = False
For Each c In DataRange.Cells
If IsDate(c.Value) Then
If Date - DateValue(c.Value) > 15 Then
If DeleteRange Is Nothing Then
Set DeleteRange = c
Else
Set DeleteRange = Union(DeleteRange, c)
End If
End If
End If
Next c
'delete all matched rows in one go
If Not DeleteRange Is Nothing Then DeleteRange.EntireRow.Delete
End Sub