travieman90
New Member
- Joined
- Aug 17, 2020
- Messages
- 6
- Office Version
- 365
- Platform
- Windows
Attempting to copy data from sheet "2020bymachine" to A3 on activesheet. Only want to copy rows containing today's or yesterdays date in column A. The code below runs and presents no errors but does not copy anything.
VBA Code:
Sub CopyData()
Dim LastRow As Long, d As Long
Dim CopyRange As Range, count As Long
LastRow = Cells(Cells.Rows.count, "A").End(xlUp).Row
For d = LastRow To 10 Step -1
If IsDate(Sheets("2020byMachine").Cells(d, "A")) And Sheets("2020byMachine").Cells(d, "A").Value = Date Then
count = count + 1
If CopyRange Is Nothing Then
Set CopyRange = Rows(d).EntireRow
Else
Set CopyRange = Union(CopyRange, Rows(d).EntireRow)
End If
End If
CopyRange.Copy
Sheets("DataSheet").Select
Range("A3").Select
ActiveSheet.Paste
End Sub
Last edited by a moderator: