nmccracken12
New Member
- Joined
- Oct 8, 2020
- Messages
- 37
- Office Version
- 365
- Platform
- Windows
I am trying to get this code to work that I found on here. I am able to change the sheet names, but I am not knowledgeable enough to know how to change the cells that matter. Code below. The expiration date sits in column I. The columns in play are A-I. Any one able to help? Thanks in advance!
Sub TransferExpired()
Dim c As Range, TransferRange As Range, DataRange As Range
Dim DestRange As Range
Dim Lr As Long
Dim iCount As Long
With ThisWorkbook
With .Sheets("PROGRAM PERIOD") 'source sheet
Lr = .Cells(.Rows.Count, 1).End(xlUp).Row
Set DataRange = .Range(.Cells(2, 1), .Cells(Lr, 1))
End With
With .Sheets("EXPIRED PROGRAMMING") 'destination sheet
Lr = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
Set DestRange = .Cells(Lr, 1)
End With
End With
DataRange.EntireRow.Hidden = False
For Each c In DataRange.Cells
If IsDate(c.Value) Then
If c.Value < Date Then
If TransferRange Is Nothing Then
Set TransferRange = c
Else
Set TransferRange = Union(TransferRange, c)
End If
iCount = iCount + 1
End If
End If
Next c
If Not TransferRange Is Nothing Then
With TransferRange.EntireRow
.Copy DestRange
.Delete
End With
End If
MsgBox iCount & " Expired Records Transferred", 48, "Expired"
End Sub
Sub TransferExpired()
Dim c As Range, TransferRange As Range, DataRange As Range
Dim DestRange As Range
Dim Lr As Long
Dim iCount As Long
With ThisWorkbook
With .Sheets("PROGRAM PERIOD") 'source sheet
Lr = .Cells(.Rows.Count, 1).End(xlUp).Row
Set DataRange = .Range(.Cells(2, 1), .Cells(Lr, 1))
End With
With .Sheets("EXPIRED PROGRAMMING") 'destination sheet
Lr = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
Set DestRange = .Cells(Lr, 1)
End With
End With
DataRange.EntireRow.Hidden = False
For Each c In DataRange.Cells
If IsDate(c.Value) Then
If c.Value < Date Then
If TransferRange Is Nothing Then
Set TransferRange = c
Else
Set TransferRange = Union(TransferRange, c)
End If
iCount = iCount + 1
End If
End If
Next c
If Not TransferRange Is Nothing Then
With TransferRange.EntireRow
.Copy DestRange
.Delete
End With
End If
MsgBox iCount & " Expired Records Transferred", 48, "Expired"
End Sub