Stuhelhall
New Member
- Joined
- Sep 25, 2012
- Messages
- 14
Hi,
I have the existing VBA code (see below) to create a CSV file from a excel sheet and this work well, however the problem is the software that reads the CSV file does not like data missing in rows or enire blank rows.
Therefore I need a macro that would amend the new CSV file as it is been created to remove entire rows when data is not present in column A.
Is this possible?
Sub CopyToCSV()
Dim MyPath As String
Dim MyFileName As String
'The path and file names:
MyPath = "C:\V10\demo\import\"
MyFileName = Sheets(1).Cells(1, 1).Value
'Makes sure the path name ends with "\":
If Not Right(MyPath, 1) = "\" Then MyPath = MyPath & "\"
'Makes sure the filename ends with ".csv"
If Not Right(MyFileName, 4) = ".csv" Then MyFileName = MyFileName & ".csv"
'Copies the sheet to a new workbook:
Sheets("upload").Copy
'The new workbook becomes Activeworkbook:
With ActiveWorkbook
'Saves the new workbook to given folder / filename:
.SaveAs Filename:= _
MyPath & MyFileName, _
FileFormat:=xlCSV, _
CreateBackup:=False
'Closes the file
.Close False
End With
End Sub
Thanks in anticipation.
Stuart
I have the existing VBA code (see below) to create a CSV file from a excel sheet and this work well, however the problem is the software that reads the CSV file does not like data missing in rows or enire blank rows.
Therefore I need a macro that would amend the new CSV file as it is been created to remove entire rows when data is not present in column A.
Is this possible?
Sub CopyToCSV()
Dim MyPath As String
Dim MyFileName As String
'The path and file names:
MyPath = "C:\V10\demo\import\"
MyFileName = Sheets(1).Cells(1, 1).Value
'Makes sure the path name ends with "\":
If Not Right(MyPath, 1) = "\" Then MyPath = MyPath & "\"
'Makes sure the filename ends with ".csv"
If Not Right(MyFileName, 4) = ".csv" Then MyFileName = MyFileName & ".csv"
'Copies the sheet to a new workbook:
Sheets("upload").Copy
'The new workbook becomes Activeworkbook:
With ActiveWorkbook
'Saves the new workbook to given folder / filename:
.SaveAs Filename:= _
MyPath & MyFileName, _
FileFormat:=xlCSV, _
CreateBackup:=False
'Closes the file
.Close False
End With
End Sub
Thanks in anticipation.
Stuart