Hello all,
I have the below code however i need to edit the CSV data before it saves as currently the copy and past section looses the formating.
Sub save_to_CSV()
Dim myCSVFileName As String
Dim myWB As Workbook
Dim tempWB As Workbook
Dim rngToSave As Range
Application.DisplayAlerts = False
On Error GoTo err
Set myWB = ThisWorkbook
myCSVFileName = myWB.Path & "\" & "Staffingfile-" & VBA.Format(VBA.Now, "dd-MMM-yyyy hh-mm") & ".csv"
Set rngToSave = Range("B2:F300")
rngToSave.Copy
Set tempWB = Application.Workbooks.Add(1)
With tempWB
.Sheets(1).Range("A1").PasteSpecial xlPasteValues
.SaveAs Filename:=myCSVFileName, FileFormat:=xlCSV, CreateBackup:=False
.Close
End With
err:
Application.DisplayAlerts = True
End Sub
This is the section that im looking to do in the CSV the following
Columns("D:D").Select
Selection.NumberFormat = "yyyy-mm-dd"
'
Range("A1").Select
ActiveCell.FormulaR1C1 = "CountryCode"
Range("B1").Select
ActiveCell.FormulaR1C1 = "StationCode"
Range("C1").Select
ActiveCell.FormulaR1C1 = "TrainingName"
Range("D1").Select
ActiveCell.FormulaR1C1 = "Date"
Range("E1").Select
ActiveCell.FormulaR1C1 = "Capacity"
Thanks for your help.
Bookmarks