Hi Richard,
Worked like a charm. Had to edit slightly, pasted the values in to A1 and removed the line about deleting columns A:L. See complete working code below. Thank you for all of your help.
Sub CopyToCSV()
Dim MyPath As String
Dim MyFileName As String
'The path and file names:
MyPath = "G:\JSM & SYNERGY\JSM & SYNERGY\Dom TEST\MailMerge\CSV Files"
MyFileName = InputBox("Enter file name") & " " & 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("PIVOT").Copy
'The new workbook becomes Activeworkbook:
With ActiveWorkbook
'Replaces Pivot Data with Values only
With ActiveSheet.PivotTables("PivotTable1")
.PivotSelect ""
Selection.Copy
Range("A1").PasteSpecial (xlPasteValuesAndNumberFormats)
'Deletes rows 1 to 8
Rows("1:8").Delete
End With
'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
Kind regards,
Dom
Bookmarks