Hi,
I can't get my my date to display in the format that I want it to as a string variable in vba.
The msgbox displays 3/21/2017
The value in B1 shows as 3-21-2017
I want the variable "Today" to use the -'s so that I can use it to save in a filename. Does anyone know how to get VBA to display the -'s instead?
I even tried using some left, mid, right commands to pull the dates, but it doesn't seem to recognize the date format that the cell is saved into and always defaults to m/d/yyyy, so that doesn't work very well. I could add some if statements for months/days that are two digits, but I was curious if anybody knew why it defaults to /'s and how to avoid that.
I can't get my my date to display in the format that I want it to as a string variable in vba.
Code:
Public Sub Todaydate()
Today = Sheets("Date").Range("B1").Value
MsgBox Today
End Sub
The msgbox displays 3/21/2017
The value in B1 shows as 3-21-2017
I want the variable "Today" to use the -'s so that I can use it to save in a filename. Does anyone know how to get VBA to display the -'s instead?
I even tried using some left, mid, right commands to pull the dates, but it doesn't seem to recognize the date format that the cell is saved into and always defaults to m/d/yyyy, so that doesn't work very well. I could add some if statements for months/days that are two digits, but I was curious if anybody knew why it defaults to /'s and how to avoid that.
Code:
Public Sub Todaydate()
Today = Left(Sheets("Date").Range("B1").Value, 2) & "-" & Mid(Sheets("Date").Range("B1").Value, 4, 2) & "-" & Right(Sheets("Date").Range("B1").Value, 4)
MsgBox Today
End Sub