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..........
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Check out the worksheet change event procedure. Search XL VBA help for 'change event' or better yet 'sheetchange event' (both w/o the quotes).
 
Upvote 0
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?
 
Upvote 0
What is the cell in which you enter the ticker symbol?

Do you type in the symbol? Or update it some other way?
 
Upvote 0
OK. So, what row and column does AI7 correspond to? And, what row and column are you testing for in the worksheet_change procedure?
 
Upvote 0
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
 
Upvote 0
You are welcome. Of course, you did most of the work. I just pointed you in the right direction.
 
Upvote 0

Forum statistics

Threads
1,213,530
Messages
6,114,162
Members
448,554
Latest member
Gleisner2

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