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.
 

Some videos you may like

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

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>
 

Watch MrExcel Video

Forum statistics

Threads
1,122,481
Messages
5,596,399
Members
414,063
Latest member
N_Bates

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