Hey everyone,
I am trying to export specific range of cells from excel sheet to CSV. In my case it should start from Row 3 and stop with last row and columns should be A:G
I am pretty amateurish with VBA so most of things I google and compile yet, but im stuck at this moment.
Ive got below macro but it exports whole sheet and I need to skip first 2 rows and stop at column G.
Thank you guys in advance
Sub CopyToCSV()
Dim MyPath As String
Dim MyFileName As String
'The path and file names:
MyPath = "C:\Temp"
MyFileName = "MyFileName" & Format(Date, "ddmmyy")
'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
I am trying to export specific range of cells from excel sheet to CSV. In my case it should start from Row 3 and stop with last row and columns should be A:G
I am pretty amateurish with VBA so most of things I google and compile yet, but im stuck at this moment.
Ive got below macro but it exports whole sheet and I need to skip first 2 rows and stop at column G.
Thank you guys in advance
Sub CopyToCSV()
Dim MyPath As String
Dim MyFileName As String
'The path and file names:
MyPath = "C:\Temp"
MyFileName = "MyFileName" & Format(Date, "ddmmyy")
'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