在Excel中将x轴的最大值和最小值设置为date

我有一个在x轴上有date的graphics,我试图使用Excel VBA为该轴设置最大值和最小值。 下面是我的代码似乎不工作。可以任何人请帮助。

With ActiveSheet.ChartObjects(1).Chart.Axes(xlValue) .MinimumScale = ActiveSheet.Range("C33").Value .MaximumScale = ActiveSheet.Range("D54").Value End With 

xlValue是指y轴(或数值轴)。 您有兴趣调整需要xlCategory的x轴值(或类别轴)。 所以使用

 With ActiveSheet.ChartObjects(1).Chart.Axes(xlCategory) .MinimumScale = ActiveSheet.Range("C33").Value .MaximumScale = ActiveSheet.Range("D54").Value End With 

我为二元正态分布创build了一个图表。 X1遵循mu1和stdev1的正态分布,对于X2也是如此。 X1是沿着X轴的。 我希望限制在平均值的4个标准偏差之内。 mywidth和myheight被预先分配。 数据从第2行开始,因为第1行有标题。X1的数据位于第1列。 n是数据的行数。

 mysheetname = ActiveSheet.Name Set mychart = Sheets(mysheetname).ChartObjects.Add(Left:=mywidth, Top:=myheight + 2, Width:=400, Height:=250) mychart.Chart.ChartType = xlXYScatter mychart.Chart.SeriesCollection.NewSeries mychart.Chart.SeriesCollection(1).Values = Range(Cells(outputrow + 1, outputcol + 1), Cells(outputrow + n, outputcol + 1)) mychart.Chart.SeriesCollection(1).XValues = Range(Cells(outputrow + 1, outputcol), Cells(outputrow + n, outputcol)) mychart.Chart.HasLegend = False mychart.Chart.Axes(xlValue).MinimumScale = mu2 - 4 * sigma2 mychart.Chart.Axes(xlValue).MaximumScale = mu2 + 4 * sigma2 mychart.Chart.Axes(xlCategory).MinimumScale = mu1 - 4 * sigma1 mychart.Chart.Axes(xlCategory).MaximumScale = mu1 + 4 * sigma1