Dear All,
I have a macro which copy and paste my graph to another workbook delinking the source. The problem appears when on my original "X" there are some gaps in dates (because I reflect some data on working days). Therefore, the copied version substitute the original dates with the gaps one. For example: the original contains 8th,9th, 12th and 13th of September then the copied will return 8th, 9th, 10th and 11th of September. This is my current macro:
I would really appreciate for any help!
I have a macro which copy and paste my graph to another workbook delinking the source. The problem appears when on my original "X" there are some gaps in dates (because I reflect some data on working days). Therefore, the copied version substitute the original dates with the gaps one. For example: the original contains 8th,9th, 12th and 13th of September then the copied will return 8th, 9th, 10th and 11th of September. This is my current macro:
Code:
[FONT=Arial]Sub save_file()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>[/FONT]
[FONT=Arial] Dim twb As Workbook, wb As Workbook, chtCopy As ChartObject, objSeries As Series<o:p></o:p>[/FONT]
[FONT=Arial] Set twb = ThisWorkbook<o:p></o:p>[/FONT]
[FONT=Arial]<o:p> </o:p>[/FONT]
[FONT=Arial] new_sheet_counter = Application.SheetsInNewWorkbook<o:p></o:p>[/FONT]
[FONT=Arial] Set wb = Workbooks.Add<o:p></o:p>[/FONT]
[FONT=Arial]<o:p> </o:p>[/FONT]
[FONT=Arial]'----- Copy relevant worksheets to new book -----<o:p></o:p>[/FONT]
[FONT=Arial] twb.Sheets("Currency Dashboard").Copy after:=wb.Sheets(new_sheet_counter)<o:p></o:p>[/FONT]
[FONT=Arial]'----- Remove original worksheets and set others to values-only -----<o:p></o:p>[/FONT]
[FONT=Arial] Application.DisplayAlerts = False<o:p></o:p>[/FONT]
[FONT=Arial] With wb<o:p></o:p>[/FONT]
[FONT=Arial] For counter = 1 To new_sheet_counter<o:p></o:p>[/FONT]
[FONT=Arial] .Sheets("Sheet" & counter).Delete<o:p></o:p>[/FONT]
[FONT=Arial] Next<o:p></o:p>[/FONT]
[FONT=Arial] .Colors = twb.Colors<o:p></o:p>[/FONT]
[FONT=Arial] For Each ws In wb.Worksheets<o:p></o:p>[/FONT]
[FONT=Arial] ws.Cells.Copy<o:p></o:p>[/FONT]
[FONT=Arial] ws.Cells.PasteSpecial (xlPasteValues)<o:p></o:p>[/FONT]
[FONT=Arial] Application.CutCopyMode = False<o:p></o:p>[/FONT]
[FONT=Arial] For Each chtCopy In ws.ChartObjects<o:p></o:p>[/FONT]
[FONT=Arial] For Each objSeries In chtCopy.Chart.SeriesCollection<o:p></o:p>[/FONT]
[FONT=Arial] objSeries.XValues = objSeries.XValues<o:p></o:p>[/FONT]
[FONT=Arial] objSeries.Values = objSeries.Values<o:p></o:p>[/FONT]
[FONT=Arial] objSeries.Name = objSeries.Name<o:p></o:p>[/FONT]
[FONT=Arial] Next<o:p></o:p>[/FONT]
[FONT=Arial] Next<o:p></o:p>[/FONT]
[FONT=Arial] ws.Range("A1").Select<o:p></o:p>[/FONT]
[FONT=Arial] Next<o:p></o:p>[/FONT]
[FONT=Arial] wb.Sheets("Currency Dashboard").Select<o:p></o:p>[/FONT]
[FONT=Arial]<o:p> </o:p>[/FONT]
[FONT=Arial] End With<o:p></o:p>[/FONT]
[FONT=Arial] Application.DisplayAlerts = True<o:p></o:p>[/FONT]
[FONT=Arial]'----- Set up variables for saving report -----<o:p></o:p>[/FONT]
[FONT=Arial] reportingdate = Format(Date, "dd-mmm-yyyy")<o:p></o:p>[/FONT]
[FONT=Arial] outputlocation = coding.Range("b1")<o:p></o:p>[/FONT]
[FONT=Arial] If Right(outputlocation, 1) <> "\" Then outputlocation = outputlocation & "\"<o:p></o:p>[/FONT]
[FONT=Arial] vsion = 1<o:p></o:p>[/FONT]
[FONT=Arial]'----- Save new workbook with version control -----<o:p></o:p>[/FONT]
[FONT=Arial] Application.DisplayAlerts = False<o:p></o:p>[/FONT]
[FONT=Arial] wb.SaveAs Filename:=outputlocation & "Currency and Interest Rate Dashboard-" & reportingdate & "-" & Format(Time, "hh-mm") & ".xlsx"<o:p></o:p>[/FONT]
[FONT=Arial] wb.Close False<o:p></o:p>[/FONT]
[FONT=Arial] Application.DisplayAlerts = True<o:p></o:p>[/FONT]
[FONT=Arial]End Sub<o:p></o:p>[/FONT]
[FONT=Arial]Private Function FileExists(fname) As Boolean<o:p></o:p>[/FONT]
[FONT=Arial]'----- Returns TRUE if the file exists -----<o:p></o:p>[/FONT]
[FONT=Arial] Dim x As String<o:p></o:p>[/FONT]
[FONT=Arial] x = Dir(fname)<o:p></o:p>[/FONT]
[FONT=Arial] If x <> "" Then FileExists = True Else FileExists = False<o:p></o:p>[/FONT]
[FONT=Arial]End Function<o:p></o:p>[/FONT]