sorry, i meant
If Not Application.Intersect(Targ
Sébastien
Main Topics
Browse All TopicsHi, I just wondered if anyone could tell me why the following code won't work - its supposed to update a graph scale as every time a cell - B4 - is changed
The code is;
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = Range("B4").Address Then
MsgBox "hello"
Set Xscale = Range("B4")
ActiveSheet.ChartObjects("
With ActiveChart.Axes(xlCategor
.MinimumScale = 0
.MaximumScale = Xscale
.MinorUnitIsAuto = True
.MajorUnitIsAuto = True
.Crosses = xlCustom
.CrossesAt = 0
.ReversePlotOrder = False
.ScaleType = xlLinear
End With
End
End Sub
The msgbox doesn't even work
Any ideas?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
If even Zmey2' code doesn't work then maybe you have got events turned off somehow?
Try this:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
MsgBox "does this work"
end sub
If that doesn't respond with a message box when you change a cell on that sheet then go to the VBA editor and press Control_G to bring up the immediate window and type:
Application.EnableEvents=T
and hit enter. Now try changing a cell.
Steve
Calm down..... :-)
OK, the code is as simple as it gets and does work so there is obviously something odd with your workbook or Xl installation. Have you had any macros running from worksheet events before on this PC and/or does it work if you start a fresh new workbook with just this code in?
I presume you are adding the code to one of the sheets areas and not workbook or a module? Sorry, but have to ask.
Steve
Ahh I see :-) Try right clicking on one of the sheets "tabs" in Xl itself and choosing View Code or go into VBA editor (Alt F11) and open project Explorer. Code related to a sheet needs to go into that sheet so double click on Sheet1, for instance and it will give you a code area related to Sheet1. Likewise the ThisWorkbook area relates to the whole workbook.
Try pasting the code in there and you should find it kicks off now ...
hth
Steve
Ok, seems to have lost a repl of mine, so I apologisie if this is posted twice - I waited 5 mins, and nothing hapeened, so....
Anyway, I did know about the sheet code, in a removed, I knew I could but am stupid way. The code that was for the button that does this was already there!
My final code, for changing the axis of a graph depending on the value of two cells is...
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Address = "$B$4" Then
Set Xscale = Range("$B$4")
ActiveSheet.ChartObjects("
With ActiveChart.Axes(xlCategor
.MinimumScale = 0
.MaximumScale = Xscale
.MinorUnitIsAuto = True
.MajorUnitIsAuto = True
.Crosses = xlCustom
.CrossesAt = 0
.ReversePlotOrder = False
.ScaleType = xlLinear
End With
ElseIf Target.Address = "$B$5" Then
Set Yscale = Range("$B$5")
ActiveSheet.ChartObjects("
With ActiveChart.Axes(xlValue)
.MinimumScale = 0
.MaximumScale = Yscale
.MinorUnitIsAuto = True
.MajorUnitIsAuto = True
.Crosses = xlCustom
.CrossesAt = 0
.ReversePlotOrder = False
.ScaleType = xlLinear
End With
End If
End Sub
Business Accounts
Answer for Membership
by: sebastienmPosted on 2003-01-31 at 01:49:53ID: 7851895
Instead of et,Range(" A4")) Then
If Target.Address = Range("B4").Address Then
try
If Not Application.Intersect(Targ
does it work?
Sébastien