Chart Axis range update based on cell values

rjplante

Well-known Member
Joined
Oct 31, 2008
Messages
569
Office Version
  1. 365
Platform
  1. Windows
I have a 52 week bar chart with data being entered for each week as the data is obtained. I have two cells on the chart sheet and I would like the chart to display the start week and end week as defined by those cell values. I have included my macro and an image of my chart. I don't know how to get my chart to resize the X axis based on the two cells of data (C4 for Start Date and D4 for End Date).

When I run my macro, I get the following error:

Run-time error '-214767259 (80004005)': Method 'MaximumScale' of object 'Axis' failed.

The following line is highlighted when debug is selected:

.MaximumScale = Worksheets("Charts").Range("D4").Value

Macro:
VBA Code:
Sub RefreshChart()
 
'The With ... End With statement allows you to write shorter code by referring to an object only once instead of using it with each property.
'The Axis object has one argument, choose between xlCategory, xlSeriesAxis, or xlValue

With Worksheets("Charts").ChartObjects("Chart 21").Chart.Axes(xlCategory)

    'Change maximum scale for Chart 1 on Data Worksheet to value in cell D4
    .MaximumScale = Worksheets("Charts").Range("D4").Value

    'Change minimum scale for Chart 1 on Data Worksheet to value in cell C4
    .MinimumScale = Worksheets("Charts").Range("C4").Value

End With

End Sub

Page Layout:
Sales Tracker 18-MAY-2020.xlsm
ABCDEFG
1MayMay
2Quarter
3Date Range1-May-202031-May-2020
4Week:1823
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Charts
Cell Formulas
RangeFormula
C4:D4C4=WEEKNUM(C3)
Cells with Data Validation
CellAllowCriteria
C1:D1List=Month
E3List=Quarter


Chart:
1590585401200.png
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Forum statistics

Threads
1,214,926
Messages
6,122,305
Members
449,079
Latest member
juggernaut24

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