Changing date on vba code.

akeem1234

New Member
Joined
Nov 7, 2022
Messages
24
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hi so i have a code that removes dates that are either less than the start date or more than the end date. I want to change the start from today instead of from 8 + days.
below is the code I have:

'next Tuesday as the start date

start_dt = CDate(Date + 8 - Weekday(Date, vbMonday))

' Tuesday in 2 weeks as the end date

end_dt = CDate(Date + 22 - Weekday(Date, vbTuesday))

'Delete items with dates beyond the dates

sh4.Activate

With sh4

For i = LastRow4 To 2 Step -1

If CDate(.Cells(i, 3).Value) < start_dt Or CDate(.Cells(i, 3).Value) > end_dt Then

.Rows(i).EntireRow.delete shift = xlUp



End If



With this code I thought I could change the start date from 8 to 0 but it still runs the same code and removes everything from before 8+ days.
could someone please advise how i could rearrange and change this code so that the start date is from the day i run it. (T0)
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
In what way doesn't it work? btw I would try
VBA Code:
start_dt = CDate(Date)
 
Upvote 0

Forum statistics

Threads
1,215,172
Messages
6,123,438
Members
449,100
Latest member
sktz

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
Back
Top