I have the following function in my worksheet...
Format(Range("AG1"), "mm")
I'm using it to auto-populate the saveas filename, which is a larger function, but it all works except for this part. As part of that larger function there is
Year(Range("AG1"))
which is returning the correct year in "yyyy" format. (It doesn't require any specific formatting, it just returns the year in 4-digit format.)
However, the first function, Format(Range("AG1"), "mm")
is always returning 01, indicating that is is January, which it isn't always. I need the month based on the current date to be returned in "mm" format.
The Range("AG1")
refers to a cell in the worksheet that has a date entered as [mm/dd/yyyy]
.
Any ideas what I'm doing wrong?
04/02/2017
into AG1, does your function now return 2? And is your locale set to use "dd/mm/yyyy" format? If you have text in the cell, and Excel can interpret it as a valid dd/mm/yyyy date, it will. If it can't, it will try to interpret it as a mm/dd/yyyy date. - YowE3K