Excel - A macro to edit file name

Ask a question



Issue


I have a macro code to save a file name to a form. My file takes two cells (F4) and (H20) to create a backup file. I wan put a hyphen between the two cells nd tried this:

File_Name = Worksheets("Sheet1").Range("F4") & Worksheets("Sheet1").Range("H20") & ".xlsm"


The result generated takes this form F4H20 and I wish it was F4-H20.

Solution


Try this:

File_Name = Worksheets("Sheet1").Range("F4") & "-" & Worksheets("Sheet1").Range("H20") & ".xlsm" 


Thanks to f894009 for this tip.
Jean-François Pillou

CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jeff Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.

Learn more about the CCM team