I have a table in Excel that I have to export to CVS. The table is like:
I have the following code to export to CSV:
Columns("A:D").Copy
Workbooks.Add
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:="C:\x_test.csv" _
, FileFormat:=xlCSV, CreateBackup:=False
ActiveWindow.Close
Application.DisplayAlerts = True
The output is like:
Book Title,,,
Author,Total Pages,Editor,Year Published
Adam,50,Universal,2018
Section,Pages,,
1,20,,
2,30,,
The problem I have is that it adds additional cells in rows that I don't need. for example, the first line should be like "Book Title" not like "Book Title,,,"
Is there a way to export to CSV with the relevant number of columns properly reflected with comas for each line
I tried merging the cells in Excel, but it did not make any difference.