Hello, Could you be so kind and help me with VBA, please? I would like to save the below example as CSV via marco. There will be only data in column C as result of formula but the header data needs to be in separated columns A B C D on csv also if there will be no data e.g. C5 the result of a formula will be "" and will be great if will be possible not to include "" on the csv/txt. The CSV will also need to be saved in the same folder what xlsx (the working on workbook). I have managed to get macro to save only column C ( Header C1 and data from C2,C3,C4 and C5 with "" which is not ideal) with data but without headers from A1 B1 and D1. Thank you so much for you help and guidance.
Sub saveABCDToCSV()
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 & "\" & "ABCD-" & VBA.Format(VBA.Now, "dd-MMM-yyyy") & ".csv"
Set rngToSave = Range("C1:C5")
rngToSave.Copy
Set tempWB = Application.Workbooks.Add(1)
With tempWB
.Sheets(1).Range("A1").PasteSpecial xlPasteValues
.SaveAs Filename:=myCSVFileName, FileFormat:=xlCSV, CreateBackup:=False
.Close
MsgBox "CSV created"
End With
err:
Application.DisplayAlerts = True
End Sub
Sub saveABCDToCSV()
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 & "\" & "ABCD-" & VBA.Format(VBA.Now, "dd-MMM-yyyy") & ".csv"
Set rngToSave = Range("C1:C5")
rngToSave.Copy
Set tempWB = Application.Workbooks.Add(1)
With tempWB
.Sheets(1).Range("A1").PasteSpecial xlPasteValues
.SaveAs Filename:=myCSVFileName, FileFormat:=xlCSV, CreateBackup:=False
.Close
MsgBox "CSV created"
End With
err:
Application.DisplayAlerts = True
End Sub