Help with replacing "/" with "_" in date formula

tmpollard

Board Regular
Joined
Jun 12, 2008
Messages
111
Hello all,
Please help me with a formula to fix my date. In cell A10 I have a date 06/17/23, my macro concatenates a text cell with this date and it looks similar to this in cell A11 "Daily Report 06/17/2023".

The contents of A11 are used in the macro to save the file but it kicks it out because you can't save the file with "/" in the name. How can I enter a formula to change the "/" to "_" so the file will save.

End goal is to have a name like "Daily Report 06_17_2023" so the file will save.
Thanks
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Is the value in cell A10 actually entered as a Date or Text?
If it is entered as a valid date, you can do this to build the name in VBA:
VBA Code:
Dim fName as String
fName = "Daily Report " & Format(Range("A10").Value,"mm_dd_yyyy")
 
Upvote 0
This is how the date gets into cell A10, the cell is formatted as a date. Do I put your code in here somewhere?


Sub SetDate()
'
' SetDate Macro

With Range("A10")
.Value = Date
.NumberFormat = "mm/dd/yy"


End With
End Sub
 
Upvote 0
This is how the date gets into cell A10, the cell is formatted as a date. Do I put your code in here somewhere?


Sub SetDate()
'
' SetDate Macro

With Range("A10")
.Value = Date
.NumberFormat = "mm/dd/yy"


End With
End Sub
Yes, you put my code in the macro you are using to save the file. That is not the one that you posted.

Note that in your code above, it looks like you are just placing the current date in cell A10.
If all you are using A10 is to build your file name, you may not even need that code above, as you can build the file name directly without having to reference cell A10, like this:
VBA Code:
Dim fName as String
fName = "Daily Report " & Format(Date,"mm_dd_yyyy")

If you are having trouble where to put this all in your code, please post the code you currently have to save the file.
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,206
Members
453,022
Latest member
RobertV1609

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top