automatic chart scaling

cheveley

Active Member
Joined
Sep 24, 2002
Messages
273
i have some code that adjusts the scale of a share price graph to the correct dollar scale depending on which company is selected. my problem is that the scaling code works fine, but i cant seem to get the code to automatically execute every time a new company is selected. a new company is selected by inputting the company ticker i.e. MSFT in a cell.

my code is as follows;

Public Sub UpdateChartScales()

Dim intMin As Variant
Dim intMax As Variant

'P and Q Axis Adj
Application.Goto Reference:="gmax"
intMax = ActiveCell.Value
Application.Goto Reference:="gmin"
intMin = ActiveCell.Value

Sheets("iWATCH").Select
ActiveSheet.ChartObjects("Chart 6").Activate
ActiveChart.Axes(xlValue).Select

With ActiveChart.Axes(xlValue)
.MinimumScale = intMin
.MaximumScale = intMax
.MinorUnitIsAuto = True
.MajorUnitIsAuto = True
End With

End Sub


thanks..........
 

Some videos you may like

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

tusharm

MrExcel MVP
Joined
May 28, 2002
Messages
11,028
Check out the worksheet change event procedure. Search XL VBA help for 'change event' or better yet 'sheetchange event' (both w/o the quotes).
 

cheveley

Active Member
Joined
Sep 24, 2002
Messages
273
thanks for that, done the reading up - partially makes sense and i now have the following code in the worksheet where the company ticker gets changed;

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row = 6 And Target.Column = 36 Then
UpdateChartScales
End If
End Sub

unfortunately the codes still does not execute. i have checked re-checked names and references but no luck.

could i be missing something else?
 

tusharm

MrExcel MVP
Joined
May 28, 2002
Messages
11,028
What is the cell in which you enter the ticker symbol?

Do you type in the symbol? Or update it some other way?
 

cheveley

Active Member
Joined
Sep 24, 2002
Messages
273

ADVERTISEMENT

cell ai7 and i type the ticker in
 

tusharm

MrExcel MVP
Joined
May 28, 2002
Messages
11,028
OK. So, what row and column does AI7 correspond to? And, what row and column are you testing for in the worksheet_change procedure?
 

cheveley

Active Member
Joined
Sep 24, 2002
Messages
273
i think i have solved the problem. i have two seperatly merged areas above cell ai7 (this cell is not merged) and i think this is corrupting the R7C36 reference. when i change the cell in which i input the company away from the merged area the code works 100%.

thanks very much for all your help tusharm
 

tusharm

MrExcel MVP
Joined
May 28, 2002
Messages
11,028
You are welcome. Of course, you did most of the work. I just pointed you in the right direction.
 

Watch MrExcel Video

Forum statistics

Threads
1,119,264
Messages
5,577,081
Members
412,763
Latest member
sienweiw
Top