Converting Excel Formula to VBA Script

euge_prime2001

New Member
Joined
Aug 4, 2017
Messages
8
Hi Guys,
I would like to ask your help how to convert these excel formula into VBA Script:
Beg_Date: =DATE(YEAR(TODAY())-1,10,1)
End_Date: =TODAY()
Week No: = Beg_Date-End_Date

Thanks a lot for your help!

Regards,
Eugene
 
Noted Joe. The formula works fine now:

mBegDate = DateSerial(Year(Now()) - 1, 10, 1)
mEndDate = Now()
mWKNum = Application.RoundUp((mEndDate - mBegDate) / 7, 0)
MsgBox mWKNum

Regards,
Eugene
 
Upvote 0

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Ah, yes. One point of clarification I should have mentioned earlier. In VBA, Now() includes a time component. Date does not.
So, if you want current date and time, use Now().
If you just want the current date, use Date.

Based on your calculations, I didn't think you really wanted to include the time.
Note that if you are checking to see if two dates are equal, you probably do not want to include the time piece, or it probably won't work!
Now() = Date for only one second each day (at exactly midnight)!
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,678
Members
449,116
Latest member
HypnoFant

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