Hope everybody is fine.
I am stuck with a problem. what i am trying to do is subtract dates of column C from column AQ dates.
the logic is
if aq - c <= 20 then
copy entire row to sheet1
else copy entire row to sheet2.
column c contains empty cells it should automatically go to sheet 2 right?
if not i want to copy all the empty cell on column c to sheet2.
the problem i am facing is its copying all the rows to the sheet1, in different levels. nothing is going to the sheet2.
the code is here.
I am stuck with a problem. what i am trying to do is subtract dates of column C from column AQ dates.
the logic is
if aq - c <= 20 then
copy entire row to sheet1
else copy entire row to sheet2.
column c contains empty cells it should automatically go to sheet 2 right?
if not i want to copy all the empty cell on column c to sheet2.
the problem i am facing is its copying all the rows to the sheet1, in different levels. nothing is going to the sheet2.
the code is here.
Code:
Sub tesst()
Dim RowNo As Long
Dim FirstDate, SecondDate As Date
Dim ws, ws1, ws2 As Worksheet
Set ws = ThisWorkbook.Sheets("Updated_Date_Exceeded_data")
Set ws1 = ThisWorkbook.Sheets("Sheet1")
Set ws2 = ThisWorkbook.Sheets("Sheet2")
RowNo = 2
Do Until ws.Cells(RowNo, 1) = ""
FirstDate = ws.Cells(RowNo, 43)
SecondDate = ws.Cells(RowNo, 3)
If DateDiff("d", FirstDate, SecondDate) <= 20 Then
ws.Cells(RowNo, 1).EntireRow.Copy Destination:=ws1.Cells(RowNo, 1)
Else: ws.Cells(RowNo, 1).EntireRow.Copy Destination:=ws2.Cells(RowNo, 1)
End If
RowNo = RowNo + 1
Loop
End Sub