Hi,
I am wanting to copy 7 tabs to a new workbook on the click of a button. I have the below code which works mostly ok there are just a few issues.
1. The source data has filtered pivot tables in it and when it exports it exports all the pivot data rather then just what was filtered down
2. There are some hidden rows and columns in the source data but when I export it they dont go across as hidden
3. Some pivot tables are converting back to non pivot areas and as a result throwing off Legends on the charts that are there
4. Some merged cells are unmerging
I am guessing the main issue is the coding which says pasted values. Is there a way around this, also would i better doing the tabs one by one as each tab has a different set up, as in one might have charts and another might be just pivots.
The file needs to export to an XLSX file as someone else will need to edit it afterwards. All help greatly appreciated
I am wanting to copy 7 tabs to a new workbook on the click of a button. I have the below code which works mostly ok there are just a few issues.
1. The source data has filtered pivot tables in it and when it exports it exports all the pivot data rather then just what was filtered down
2. There are some hidden rows and columns in the source data but when I export it they dont go across as hidden
3. Some pivot tables are converting back to non pivot areas and as a result throwing off Legends on the charts that are there
4. Some merged cells are unmerging
I am guessing the main issue is the coding which says pasted values. Is there a way around this, also would i better doing the tabs one by one as each tab has a different set up, as in one might have charts and another might be just pivots.
VBA Code:
Sub Newsletter()
Dim FP As String
Dim NewName As String
Dim nm As Name
Dim ws As Worksheet
FP = "D:\Users\R45454\Desktop\Lance\Reporting\"
Call Refershall
'If MsgBox("Copy specific sheets to a new workbook" & vbCr & _
' "New sheets will be pasted as values, named ranges removed" _
' , vbYesNo, "NewCopy") = vbNo Then Exit Sub
Application.DisplayAlerts = False
With Application
.ScreenUpdating = False
On Error GoTo ErrCatcher
Sheets(Array("Report1", "Report3", "Report4", "Report5", "Report3=6", "Report7", "Report2")).Copy
On Error GoTo 0
' Paste sheets as values
' Remove External Links, Hperlinks and hard-code formulas
' Make sure A1 is selected on all sheets
For Each ws In ActiveWorkbook.Worksheets
ws.Cells.Copy
ws.[A1].PasteSpecial Paste:=xlValues
ws.Cells.Hyperlinks.Delete
Application.CutCopyMode = False
Cells(1, 1).Select
ws.Activate
Next ws
Cells(1, 1).Select
' Remove named ranges
' For Each nm In ActiveWorkbook.Names
' nm.Delete
' Next nm
' Input box to name new file
NewName = InputBox("Please Specify the name of your new workbook", "Newsletter Export")
ActiveWorkbook.SaveAs Filename:=FP & NewName & ".xlsx"
ActiveWorkbook.Close SaveChanges:=False
.ScreenUpdating = True
End With
MsgBox "Newsletter has exported successfully"
Exit Sub
ErrCatcher:
MsgBox "Specified sheets do not exist within this workbook"
Application.DisplayAlerts = True
End Sub
The file needs to export to an XLSX file as someone else will need to edit it afterwards. All help greatly appreciated