Arrange "X" axis scale

waldymar

Board Regular
Joined
Feb 19, 2009
Messages
238
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:
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]
I would really appreciate for any help!
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

Forum statistics

Threads
1,224,567
Messages
6,179,571
Members
452,927
Latest member
whitfieldcraig

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top