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

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
The following instruction suits for you

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

Ciao :LOL:
 
Upvote 0
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>
 
Upvote 0

Forum statistics

Threads
1,218,518
Messages
6,142,929
Members
450,456
Latest member
Exidur

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