Belfast Neil
New Member
- Joined
- Jul 7, 2016
- Messages
- 11
Hi all,
I'm not a coder but am trying to get into using macros to speed up some of my workflows. I've recorded and tweaked a macro to edit down a sheet into a couple of basic columns. All seems to work fine in terms of saving it as a CSV in the last step but it also saves the original macros enabled workbook with the new CSV tab and changes. I want the original file left untouched and just a CSV file saved separately in the same path folder. Can anyone show me what I'm missing here? Any help greatly appreciated as I've messed about for 3 hours now trying to figure this out!
Sub MakeCSV()
'
' MakeCSV Macro
'
'
ActiveSheet.Copy After:=Sheets(1)
ActiveSheet.Name = "Price List CSV"
Cells.Select
Selection.Copy
Dim Name As String
Dim Spacer As String
Dim Description As String
Dim Filetype As String
Name = Range("A1").Value
Spacer = (" - ")
Description = Range("E1").Value
Filetype = (".csv")
FullName = Name & Spacer & Description & Filetype
Range("H3").Value = FullName
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.AutoFilter
Range("A:A,C:E").Select
Range("C1").Activate
Selection.Delete Shift:=xlToLeft
Rows("1:2").Select
Range("A2").Activate
Selection.Delete Shift:=xlUp
Columns("A:C").Select
Range("C1").Activate
Selection.AutoFilter
ActiveSheet.Range("$A$1:$C$712").AutoFilter Field:=3, Criteria1:= _
"=Standard", Operator:=xlOr, Criteria2:="="
Rows("2:2036").Select
Selection.Delete Shift:=xlUp
Selection.AutoFilter
Dim relativePath As String
relativePath = ThisWorkbook.Path & Application.PathSeparator & FullName
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=relativePath, FileFormat:=xlCSV
MsgBox ("CSV file has been saved")
Application.DisplayAlerts = True
' ThisWorkbook.Close
End Sub
I'm not a coder but am trying to get into using macros to speed up some of my workflows. I've recorded and tweaked a macro to edit down a sheet into a couple of basic columns. All seems to work fine in terms of saving it as a CSV in the last step but it also saves the original macros enabled workbook with the new CSV tab and changes. I want the original file left untouched and just a CSV file saved separately in the same path folder. Can anyone show me what I'm missing here? Any help greatly appreciated as I've messed about for 3 hours now trying to figure this out!
Sub MakeCSV()
'
' MakeCSV Macro
'
'
ActiveSheet.Copy After:=Sheets(1)
ActiveSheet.Name = "Price List CSV"
Cells.Select
Selection.Copy
Dim Name As String
Dim Spacer As String
Dim Description As String
Dim Filetype As String
Name = Range("A1").Value
Spacer = (" - ")
Description = Range("E1").Value
Filetype = (".csv")
FullName = Name & Spacer & Description & Filetype
Range("H3").Value = FullName
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.AutoFilter
Range("A:A,C:E").Select
Range("C1").Activate
Selection.Delete Shift:=xlToLeft
Rows("1:2").Select
Range("A2").Activate
Selection.Delete Shift:=xlUp
Columns("A:C").Select
Range("C1").Activate
Selection.AutoFilter
ActiveSheet.Range("$A$1:$C$712").AutoFilter Field:=3, Criteria1:= _
"=Standard", Operator:=xlOr, Criteria2:="="
Rows("2:2036").Select
Selection.Delete Shift:=xlUp
Selection.AutoFilter
Dim relativePath As String
relativePath = ThisWorkbook.Path & Application.PathSeparator & FullName
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=relativePath, FileFormat:=xlCSV
MsgBox ("CSV file has been saved")
Application.DisplayAlerts = True
' ThisWorkbook.Close
End Sub