Using Now() Command in VBA

Satch7

New Member
Joined
Jul 30, 2007
Messages
9
I am trying to get the macro to run the following:

Select all data in one sheet (All) and pass into another (Due) then I am asking for it to look at the date in cell F2 and delete the entire row should the date be greater than today date (now()). This should show all the risks and issues that have a raised on a date of less than today's date.

Attached is a copy of the code with the offending piece of code in red Sub due()
Sheets("All").Select
Range("A1:m50").Select
Selection.Copy
Sheets("Due").Select
Range("A1").Select
ActiveSheet.Paste
Range("f2").Select
ActiveCell.Offset(0, 0).Select
Application.ScreenUpdating = False
For i = 1 To 50
If ActiveCell.Value > Now Then
Selection.EntireRow.Delete



Else
ActiveCell.Offset(1, 0).Select
End If
Next i
Application.ScreenUpdating = False
End Sub



The macro runs fine and I can get it to delete all the data row by row however it continues to delete the rows where the date is after today's date, which is shouldn’t do.


Can anyone help?
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

joefrench

Active Member
Joined
Oct 4, 2006
Messages
357
ActiveCell.Value > Now would be dates after today.
I think you want this: ActiveCell.Value < Now
 

Satch7

New Member
Joined
Jul 30, 2007
Messages
9
I think I have confused the issue.

I want the risk log to show all risk that have a raised on date that is less than todays so I can see the old one, therefire deleting all the risks with a raised on date that is >now()

The one with a greater than today date should not be showing.
 

Forum statistics

Threads
1,181,103
Messages
5,928,077
Members
436,587
Latest member
Slicesofquince

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top