Hi Fakhfour,
The user defined function changes things a little. From what I know, you can't copy the sheet to a new workbook without generating that "#NAME" issue as the new worksheet does not have that user defined function. So, to work around this, I created a third sheet in your workbook labeled "Export". This allowed me to do a copy/paste special values from your 'Report' sheet and do the exporting from the new 'Export' sheet in order to avoid having the user defined function.
I assume the file we're working on here is a sample file, so I also included code to copy not only that data from 'Report', but the formats as well. Just in case your working file had formats you wanted to retain on your final exported report.
The code is below, and I've uploaded the updated file here. Let me know if this works for you!
Sub Export()
' Copy values from Report and paste into Export sheet.
Application.ScreenUpdating = False
Sheets("Report").Select
Cells.Select
Selection.Copy
Sheets("Export").Select
Cells.Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Sheets("Report").Select
'Export Report Data
Sheets(Array("Export")).Copy
varLinks = ActiveWorkbook.LinkSources(Type:=xlLinkTypeExcelLinks)
If IsArray(varLinks) Then
For i = LBound(varLinks) To UBound(varLinks)
ActiveWorkbook.BreakLink Name:=varLinks(i), Type:=xlLinkTypeExcelLinks
Next i
End If
ActiveSheet.Name = "Report"
Application.ScreenUpdating = True
End Sub
Zarley
Bookmarks