Hello all!
I have this VBA code intended to identify expired reagents in the sheet "Active", cut those rows and paste them in the sheet "Expired". What I want is to insert a timestamp in the next column (Column "G") for EACH of the pasted rows. The code below does the work....except for the fact that it is ONLY adding the timestamp to the first pasted row (in this case G2) and not the other pasted rows.
What am I missing? Thanks in advance!
I have this VBA code intended to identify expired reagents in the sheet "Active", cut those rows and paste them in the sheet "Expired". What I want is to insert a timestamp in the next column (Column "G") for EACH of the pasted rows. The code below does the work....except for the fact that it is ONLY adding the timestamp to the first pasted row (in this case G2) and not the other pasted rows.
What am I missing? Thanks in advance!
VBA Code:
Sub TransferData()
CarryOn = MsgBox("Have all EXPIRED reagents been removed from active stock?", vbYesNo + vbExclamation, "Expired Reagents Warning")
If CarryOn = vbYes Then
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("Active") 'source sheet
Lr = .Cells(.Rows.Count, 4).End(xlUp).Row
Set DataRange = .Range(.Cells(2, 4), .Cells(Lr, 4))
End With
With .Sheets("Expired") '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
Sheets("Expired").Range("G2").End(xlUp).Offset(1).Value = Now
.Delete
End With
End If
MsgBox iCount & " Expired Records Transferred", 48, "Expired"
End If
End Sub