Inquirer,
I took a shot at it this evening and was NOT successful at getting the plot
area width to change in proportion to the amount of x-data (although I got
close). The problem appears to result from conflict between the parent chart
object and the plot area, as well as to Excel's automatic adjustment of the
plot area size in order to accomodate the x-axis labeling. In other words,
even if you tell Excel to make the plot area a certain size and the chart
object equal to this size plus some constant, it decides to change it
according to some weird formula. Not to say that it is hopeless, just that I
exhausted the time I was willing to devote to it. Although unsuccesful, you
may find the information of value.
For the sake of experimentation, I made the chart object very large so that
adjustment of the plot area would never conflict. I then created a Dynamic
Named Range called "XVals" and another called "YVals" which respectively
contained the x- and y-data. The chart source data referenced these named
ranges (i.e. Sheet1!XVals and Sheet1!YVals). This allowed me to easily
manipulate the amount of data by either expanding the ranges or vice versa.
For the record, the x-data started in cell B5 and ranged down to an
arbitrary degree. The y-data was immediately to the right starting in cell
C5. Named ranges were defined as follows:
XVals: "=OFFSET(Sheet1!$B$5, 0, 0, COUNT(Sheet1!$B:$B), 1)"
YVals: "=Offset(XVals, 0, 1)
If you are not familiar with Dynamic Named Ranges and are interested then I
can explain on request.
The macro code I used was as follows:
Const PtsPerDay As Single = 20
Sub AdjustChart()
Dim ChtObj As ChartObject
Dim Cht As Chart
Dim n As Long
Dim Day_1 As Date, Day_n As Date
Dim Msg As String
Set ChtObj = ActiveSheet.ChartObjects(1)
Set Cht = ChtObj.Chart
n = Range("XVals").Count
Day_1 = Range("XVals")(1)
Day_n = Range("XVals")(n)
With Cht.Axes(xlCategory)
.MinimumScale = Day_1
.MaximumScale = Day_n
End With
Cht.PlotArea.Width = (Day_n - Day_1) * PtsPerDay
Msg = "Should be: " & (Day_n - Day_1) * PtsPerDay & vbCr & _
"Actual plot area width = " & Cht.PlotArea.Width
MsgBox Msg
End Sub
Note that, if done according to my directions, the plot area width should
size in proportion to the amount of x-data except for an offset. The offset
tends to vary, unfortunately. You may wish to pursue this. I have not
developed a stategy for resolving the chart object vs. plot area conflict.
Obviously it is not an option to do this.
Hope this was of some value.
Regards,
Greg