ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro needed (https://www.excelbanter.com/excel-programming/417919-macro-needed.html)

david24

Macro needed
 
I need a macro that will auto enter the week ending date into a cell. anyone
help?

JLGWhiz

Macro needed
 
Try this:

Sub lastDOW()
dif = "6" - Format(Date, "w")
lstDOW = Format(Now + dif, "d mmm yyyy")
ActiveSheet.Range("A1") = CDate(lstDOW)
End Sub

It posts the date in A1 in the sytem format as data type Date. You can
either format the cell to change it or modify the code.




"david24" wrote:

I need a macro that will auto enter the week ending date into a cell. anyone
help?


david24

Macro needed
 
Thanks, the "6" needs to be an "8" though!

"JLGWhiz" wrote:

Try this:

Sub lastDOW()
dif = "6" - Format(Date, "w")
lstDOW = Format(Now + dif, "d mmm yyyy")
ActiveSheet.Range("A1") = CDate(lstDOW)
End Sub

It posts the date in A1 in the sytem format as data type Date. You can
either format the cell to change it or modify the code.




"david24" wrote:

I need a macro that will auto enter the week ending date into a cell. anyone
help?


JLGWhiz

Macro needed
 
There are only seven days in a week. How can you use 8 and get an answer
that gives a result for Friday which is day number 6.

Friday - Thrusday = 1, Thursday + 1 = Friday
Eight - Thursday = 3, Thursday + 3 = Sunday
Eight - Friday = 4, Friday + 4 = 10 which will give the
wrong date for the end of week day.

The code should subtract the current day of the week from the end of the
week day. This gives the number of days left until the end of the week.
Then add that number to the current date to get the date for the end of week
day.

Maybe I did not understand the question.




"david24" wrote:

Thanks, the "6" needs to be an "8" though!

"JLGWhiz" wrote:

Try this:

Sub lastDOW()
dif = "6" - Format(Date, "w")
lstDOW = Format(Now + dif, "d mmm yyyy")
ActiveSheet.Range("A1") = CDate(lstDOW)
End Sub

It posts the date in A1 in the sytem format as data type Date. You can
either format the cell to change it or modify the code.




"david24" wrote:

I need a macro that will auto enter the week ending date into a cell. anyone
help?



All times are GMT +1. The time now is 11:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com