ASKER
ASKER
ASKER
Sub CopyRowsWithSpecificDate()
Dim lr As Long, i As Long
Dim Rng As Range
Dim strDate As String
strDate = "03/13/18"
lr = Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lr
If Int(Cells(i, 1)) = DateValue(strDate) Then
If Rng Is Nothing Then
Set Rng = Cells(i, 1)
Else
Set Rng = Union(Rng, Cells(i, 1))
End If
End If
Next i
If Not Rng Is Nothing Then
Rng.EntireRow.Copy Sheet2.Range("A2") 'Copying the rows to Sheet2, change it as per your requirement.
End If
End Sub
ASKER
Sub CopyRowsWithSpecificDate()
Dim lr As Long, i As Long
Dim Rng As Range
Dim strDate As Date
'Assuming the date criteria is in the cell AA1
strDate = Range("AA1").Value
lr = Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lr
If Int(Cells(i, 1)) = strDate Then
If Rng Is Nothing Then
Set Rng = Cells(i, 1)
Else
Set Rng = Union(Rng, Cells(i, 1))
End If
End If
Next i
If Not Rng Is Nothing Then
Rng.EntireRow.Copy Sheet2.Range("A2") 'Copying the rows to Sheet2, change it as per your requirement.
End If
End Sub
ASKER
ASKER
Sub CopyPreviousDayData()
Dim sws As Worksheet, dws As Worksheet
Dim slr As Long
Application.ScreenUpdating = False
Set sws = Sheets("LogArchived")
If sws.FilterMode Then sws.ShowAllData
slr = sws.Cells(Rows.Count, 2).End(xlUp).Row
On Error Resume Next
Set dws = Sheets("Yesterday's Data")
dws.Cells.Clear
On Error GoTo 0
If dws Is Nothing Then
Set dws = Sheets.Add(after:=sws)
dws.Name = "Yesterday's Data"
End If
sws.Range("B6:L" & slr).AutoFilter field:=2, Criteria1:=xlFilterYesterday, Operator:=xlFilterDynamic
sws.Range("B6:L" & slr).SpecialCells(xlCellTypeVisible).Copy
dws.Range("A1").PasteSpecial xlPasteAll
dws.UsedRange.Columns.AutoFit
sws.ShowAllData
Application.ScreenUpdating = True
End Sub
ASKER
sws.Range("B6:L" & slr).AutoFilter Field:=2, Criteria1:=TargetDate, Operator:=xlFilterDynamic
Sub CopyPreviousDayData()
Dim sws As Worksheet, dws As Worksheet
Dim slr As Long
Dim prevDate As Double
Application.ScreenUpdating = False
'Finding the previous working day
prevDate = WorksheetFunction.WorkDay(Date, -1)
Set sws = Sheets("LogArchived")
sws.AutoFilterMode = False
slr = sws.Cells(Rows.Count, 2).End(xlUp).Row
sws.Range("M7:M" & slr).Formula = "=Int(B7)"
sws.Range("M7:M" & slr).NumberFormat = "General"
On Error Resume Next
Set dws = Sheets("Yesterday's Data")
dws.Cells.Clear
On Error GoTo 0
If dws Is Nothing Then
Set dws = Sheets.Add(after:=sws)
dws.Name = "Yesterday's Data"
End If
sws.Range("M6:M" & slr).AutoFilter field:=1, Criteria1:=prevDate
sws.Range("B6:L" & slr).SpecialCells(xlCellTypeVisible).Copy
dws.Range("A1").PasteSpecial xlPasteAll
dws.UsedRange.Columns.AutoFit
sws.ShowAllData
sws.Range("M6:M" & slr).ClearContents
sws.Range("B6:L6").AutoFilter
Application.ScreenUpdating = True
End Sub
ASKER
Sheets("LogArchived").Select
Range("B7").Select
TargetDate = ActiveCell.Value 'brings back a format of: #3/14/2018 3:29:22 PM#
sws.Range("B6:L" & slr).AutoFilter field:=1, Criteria1:=TargetDate
TargetDate is: #3/14/2018 3:29:22 PM# which when filtered on returns nothing... How do I adj this value so the autofilter works?ASKER
ASKER
ASKER
Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.
TRUSTED BY
ASKER