ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Now() (https://www.excelbanter.com/excel-programming/332963-now.html)

tjh

Now()
 

Hello,

I am trying to use the below VBA code to show the words "YTD May" or the
month 45 days ago.

Something is not correct in my code, because after running it displays "YTD 5"

Range("i3").Value = "YTD " & Month(Now() - 45)

How can I correct the formatting of the Month in this code?

Thank You

Ron de Bruin

Now()
 
Hi

You can use the format function

Range("i3").Value = "YTD " & Format(Month(Date - 45), "mmm")


--
Regards Ron de Bruin
http://www.rondebruin.nl


"tjh" wrote in message ...

Hello,

I am trying to use the below VBA code to show the words "YTD May" or the
month 45 days ago.

Something is not correct in my code, because after running it displays "YTD 5"

Range("i3").Value = "YTD " & Month(Now() - 45)

How can I correct the formatting of the Month in this code?

Thank You




tjh

Now()
 
Thank You that helps the formatting. However, after inputing this
information, the month is always showing January. Why is this and how can I
get it to show May with the formula.

"Ron de Bruin" wrote:

Hi

You can use the format function

Range("i3").Value = "YTD " & Format(Month(Date - 45), "mmm")


--
Regards Ron de Bruin
http://www.rondebruin.nl


"tjh" wrote in message ...

Hello,

I am trying to use the below VBA code to show the words "YTD May" or the
month 45 days ago.

Something is not correct in my code, because after running it displays "YTD 5"

Range("i3").Value = "YTD " & Month(Now() - 45)

How can I correct the formatting of the Month in this code?

Thank You





Barb Reinhardt[_2_]

Now()
 
This may help you.

http://www.w3schools.com/vbscript/func_monthname.asp

"tjh" wrote in message
...

Hello,

I am trying to use the below VBA code to show the words "YTD May" or the
month 45 days ago.

Something is not correct in my code, because after running it displays

"YTD 5"

Range("i3").Value = "YTD " & Month(Now() - 45)

How can I correct the formatting of the Month in this code?

Thank You




Ron de Bruin

Now()
 
Oops

Range("i3").Value = "YTD " & Format(Date - 45, "mmm")

--
Regards Ron de Bruin
http://www.rondebruin.nl


"tjh" wrote in message ...
Thank You that helps the formatting. However, after inputing this
information, the month is always showing January. Why is this and how can I
get it to show May with the formula.

"Ron de Bruin" wrote:

Hi

You can use the format function

Range("i3").Value = "YTD " & Format(Month(Date - 45), "mmm")


--
Regards Ron de Bruin
http://www.rondebruin.nl


"tjh" wrote in message ...

Hello,

I am trying to use the below VBA code to show the words "YTD May" or the
month 45 days ago.

Something is not correct in my code, because after running it displays "YTD 5"

Range("i3").Value = "YTD " & Month(Now() - 45)

How can I correct the formatting of the Month in this code?

Thank You








All times are GMT +1. The time now is 03:00 PM.

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