DateAdd to Subtract a Day from a Date

nniedzielski

Well-known Member
Joined
Jan 8, 2016
Messages
598
Office Version
  1. 2019
Platform
  1. Windows
I am running a Macro that takes todays date, alters and formats it as such 07 04 18. Goes into an object, enters the date this way, scrapes data and enters into onto my spreadsheet.

this is the code:

Code:
Dim lDate As String
Dim lMonth As String
Dim lDay As String
Dim lYear As String
lDate = Date
lMonth = Format(Date, "mm")
lDay = Format(Date, "dd")
lYear = Format(Date, "yy")
lweekday = Weekday(Date, vbMonday)

What I need to do is perform this function for today date and the 14 days prior.

So what I am trying to do is get VBA to subtract a day by using:

Code:
 Date = DateAdd("d", -1, Date)
    lDate = Date
    lMonth = Format(Date, "mm")
    lDay = Format(Date, "dd")
    lYear = Format(Date, "yy")
    lweekday = Weekday(Date, vbMonday)

When I run this though I get "Run-time error '70': Permission Denied

How can I get the date to subtract?

thanks,
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
You can say lDate = Date -1 then use lDate in your subsequent formats not Date.
 
Upvote 0
is there a way though to subtract 1 from lDate? I need to go back 14 days and just wanted to keep subtracting 1 from lDate 14 times until done, unless there is an easier way to accomplish this,
 
Upvote 0
When I try that I get Run-time error '13': Type Mismatch

any reason it would do that?
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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