jeremypyle
Board Regular
- Joined
- May 30, 2011
- Messages
- 174
I have a macro that exports all sheets within the workbook to different csv files. The macro is:
Sub ExportSheetsToCSV()
Dim xWs As Worksheet
Dim xcsvFile As String
For Each xWs In Application.ActiveWorkbook.Worksheets
xWs.Copy
xcsvFile = "C:\OneDrive\Houses\Business\Online ASB Payments\CSV" & "\aaa_import" & xWs.Name & ".csv"
Application.ActiveWorkbook.SaveAs Filename:=xcsvFile, _
FileFormat:=xlCSV, CreateBackup:=False
Application.ActiveWorkbook.Saved = True
Application.ActiveWorkbook.Close
Next
End Sub
However it is also exporting the lines that have formulas but not visible data or values. Is there a way to edit this macro slightly so that it only exports the rows that have values but not import lines with no values?
Colin & Kathy Trust - 19 Jul 2022,19/07/2022,123106123456700, 10.00 ,CJ & KJ,Inv786-2020,1Clifford,061234567123400,Heatpump,ca99,1aCli,J- Z
Colin & Kathy Trust - 19 Jul 2022,19/07/2022,123106123456700, 15.00 ,CJ & KJ,,,061234567123400,Brian,ma99,,Brian & Trish Vesey wages
,,, ,,,,,,,,
,,, ,,,,,,,,
,,, ,,,,,,,,
,,, ,,,,,,,,
,,, ,,,,,,,,
,,, ,,,,,,,,
It is exporting rows 1 and 2 correctly. However lines 3 to 8 have formulas but no values. Is there a way to make this macro so that it doesn't export these rows with lots of commas?
Please note I still want to export blank cells if it is within a row that has values in other cells. However if there is an entire line with no values, I don't want these lines exported to csv
Would really appreciate anyones help with this
Sub ExportSheetsToCSV()
Dim xWs As Worksheet
Dim xcsvFile As String
For Each xWs In Application.ActiveWorkbook.Worksheets
xWs.Copy
xcsvFile = "C:\OneDrive\Houses\Business\Online ASB Payments\CSV" & "\aaa_import" & xWs.Name & ".csv"
Application.ActiveWorkbook.SaveAs Filename:=xcsvFile, _
FileFormat:=xlCSV, CreateBackup:=False
Application.ActiveWorkbook.Saved = True
Application.ActiveWorkbook.Close
Next
End Sub
However it is also exporting the lines that have formulas but not visible data or values. Is there a way to edit this macro slightly so that it only exports the rows that have values but not import lines with no values?
Colin & Kathy Trust - 19 Jul 2022,19/07/2022,123106123456700, 10.00 ,CJ & KJ,Inv786-2020,1Clifford,061234567123400,Heatpump,ca99,1aCli,J- Z
Colin & Kathy Trust - 19 Jul 2022,19/07/2022,123106123456700, 15.00 ,CJ & KJ,,,061234567123400,Brian,ma99,,Brian & Trish Vesey wages
,,, ,,,,,,,,
,,, ,,,,,,,,
,,, ,,,,,,,,
,,, ,,,,,,,,
,,, ,,,,,,,,
,,, ,,,,,,,,
It is exporting rows 1 and 2 correctly. However lines 3 to 8 have formulas but no values. Is there a way to make this macro so that it doesn't export these rows with lots of commas?
Please note I still want to export blank cells if it is within a row that has values in other cells. However if there is an entire line with no values, I don't want these lines exported to csv
Would really appreciate anyones help with this