VBA First day of the month help

Jason Sawyer

New Member
Joined
May 20, 2009
Messages
3
I turn to you all again as this site has been my best resource.

I am using an Excel macro open a Reflection session. I run this daily but the variables vary each day.

What I need is the start to be the first day of the month from yesterday. example:
From - 06012009
To - 06242009 (as today is the 06/25/09)

Here is what I tried.

sDate = VBA.Format(Now, "mmddyyyy")
fDate = Left(sDate, 2) & "01" & Right(sDate, 4)
tDate = Left(sDate, 2) & (Mid(sDate, 3, 2) - 1) & Right(sDate, 4)

And then
.Transmit fDate & Chr(13)
etc.

Well, this has proven that Excel is much smarter than I am.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Code:
tdate = format(date-1,"mmddyyyy")
fdate = left(tdate,2) & "01" & right(tdate,4)
 
Upvote 0
Jason

What do you mean by 'the first day of the month from yesterday'?
 
Upvote 0
Perhaps

Code:
Dim fdate as Date
fdate = DateValue("1" & "/" & Month(Date - 1) & "/" & Year(Date - 1))
 
Upvote 0
Jason

What do you mean by 'the first day of the month from yesterday'?

I think he meant it as follows...:

Today is 06/02/09 So first of the month from yesterday would be 06/01/09

If today is 06/01/09 the first of the month from Yesterday (05/31/09) would be 05/01/09

At least that was my take on it
 
Upvote 0

Forum statistics

Threads
1,214,849
Messages
6,121,922
Members
449,056
Latest member
denissimo

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