Date Calculation Macro

MiskaTorn

Board Regular
Joined
Mar 30, 2004
Messages
155
I'm sorry guys, this is probably simple and I did look for a solution before posting this but I did not find one.

Currently I am setting the date I want to use in my filename like this.

MyDate = Format(Date, "mm-dd-yy")

The problem is I want this to display the day previous to today.

Sorry if that didn't make sence, so if today was
01-24-05
it would set MyDate to
01-23-05

Thanks in advance for any help you guys can offer.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

chiello

Well-known Member
Joined
Jan 18, 2005
Messages
848
The following instruction suits for you

Dim maydate As Date
MyDate = Format(DateAdd("d", -1, Date), "mm-dd-yy")

Ciao :LOL:
 

Zack Barresse

MrExcel MVP
Joined
Dec 9, 2003
Messages
10,881
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
  3. Web
I can use the same functions you are, just minus 1 ...


<font face=Tahoma New><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN>

<SPAN style="color:#00007F">Sub</SPAN> foo()
    <SPAN style="color:#00007F">Dim</SPAN> MyDate <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>
    MyDate = Format(Date - 1, "mm-dd-yy")
    MsgBox MyDate
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,168,025
Messages
5,856,890
Members
431,837
Latest member
megantang

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