Excel VBA issue:
Another person had a problem with the NOW() function because they wanted it to return a static date & time w/o needing to Copy & Paste the value back. I suggested a user-defined function which correctly returns the current date & time in a static manner. The problem is that the NumberFormat property is being ignored & the result that pops out is a number.
I've tried several other formatting solutions, but these are also ignored or result in errors.
Public Function DateNow() As Date
ActiveCell.NumberFormat = "[$-en-US]m/d/yy h:mm AM/PM;@"
DateNow = Now
End Function
Expected result would be a static current date & time. To re-iterate; the code is correct except the part that says ActiveCell.NumberFormat... which is not taking effect.
Edit: I've read the comments below and tried to update it to include a call to a sub, but still no luck. Could someone direct me to the workaround? Thanks.
Public Function DateNow() As Date
DateNow = Now
Call DateSub(ActiveCell)
End Function
Public Sub DateSub(rg As Range)
rg.NumberFormat = "[$-en-US]m/d/yy h:mm AM/PM;@"
End Sub