VBA code not working as required

posfog

Board Regular
Joined
Jun 2, 2009
Messages
171
Morning All,
First off Happy New Year to you all!!

Secondly I have the following code that when i click on a graph that is assoicated with the Macro its not sizing correctly to the given cells detailed in the coding.

could anyone advise at all please?

Sub Chart6_Click()
Dim ws As Worksheet
Dim chto As ChartObject
Dim rSmall As Range, rBig As Range
Static b As Boolean
Set chto = Worksheets("Delivery Overview").ChartObjects("Chart 6")
Set rSmall = Worksheets("Delivery Overview").Range("o13:x27")
Set rBig = Worksheets("Delivery Overview").Range("D13:AY92")

If b Then
chto.BringToFront
chto.Width = rSmall.Width
chto.Height = rSmall.Height
chto.Left = rSmall.Left
chto.Top = rSmall.Top
Else
chto.BringToFront
chto.Width = rBig.Width
chto.Height = rBig.Height
chto.Left = rBig.Left
chto.Top = rBig.Top


End If
b = Not b
End Sub


Kind Regards
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Works fine for me.
What do you mean exactly by not correctly?
 
Upvote 0
Hi,
for example the graph is ether smaller or bigger than the set out cell references as shown below

Set rSmall = Worksheets("Delivery Overview").Range("o13:x27")
Set rBig = Worksheets("Delivery Overview").Range("D13:AY92")

Regards
 
Upvote 0
I see it exactly in your code and as I said imho works as it should.
 
Upvote 0
Hi KOKOSEK, thats strange then.
There isnt any settings in excel to make things like this work differently is there???

Thanks again for your replies.
 
Upvote 0
What exactly works wrong? Bigger than rBig, smaller than rSmall or move correctly in top/left but not with width/height?
 
Upvote 0

Forum statistics

Threads
1,215,049
Messages
6,122,864
Members
449,097
Latest member
dbomb1414

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