I wanted to create a VBA macro that will copy the entire row and paste it in another worksheet in Excel.
My worksheet goes from column A to D, and has about 700 rows. Column D is some random date.
Problem: I have to determine expired date (and expired date is always 'today') and copy to a new sheet named 'Expired'. What I do is find the date, highlight, copy, paste, then clear highlight, but I am having trouble pasting the cells in the worksheet named 'Expired' (only the 1st row is pasted with values)
Sub ExtractExpired()
Application.ScreenUpdating = False
Sheets("Sheet1").Select
Range("d1").Select
Selection.Offset(1, 0).Select
x = Date
Z = vbBlue
Do Until Selection.Offset(0, -2).Value = ""
If Selection.Offset(0, 0).Value < x Then 'And Selection.Offset(0, 0).Value <= x Then
Range(Selection.Offset(0, -3), Selection.Offset(0, 0)).Interior.Color = Z 'And Range(Selection.Offset(0, -3), Selection.Offset(0, 0)).Font.Color = vbBlue
'If Selection.Offset(0, 0).Interior.Color = Z Then
'r = Range("a1").End(xlDown).Row
'countexpired = 2
'For q = r To 2 Step -1
'Range(Cells(q, "a"), Cells(q, "d")).Copy
'If Selection.Offset(0, 0).Interior.Color = Z Then
'Sheets("Expired").Select
'Cells(countexpired, "A").Select
'ActiveSheet.Paste
'countexpired = countexpired + 1
'Sheets("Sheet1").Select
'End If
'Next
'Call sortItem
'Range(Selection.Offset(0, -3), Selection.Offset(0, 0)).Copy (Worksheets("Expired").Range("d1"))
'ActiveCell.EntireRow.Copy (Worksheets("Expired").Range("d1"))
'End If
End If
Selection.Offset(1, 0).Select
Loop
Application.ScreenUpdating = True
End Sub