Graph to enlarge when clicked then to go back to normal ??

posfog

Board Regular
Joined
Jun 2, 2009
Messages
171
Morning All,
I have a table with data showing on it and a small graph underneath it showing what the table is above. Due to size restrictions on this i am unable to show the graph in a decent size so wondered how i can get the graph to go full size when "Clicked" and for it to go back to normal when "Clicked" again.

Any advice would be greatly received

Regards
P
 

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

You can right-click on the chart and assign a macro to toggle between the 2 sizes.
 
Upvote 0
This is a very simple example that you can adapt.

Let's assume that you have just 1 chart in worksheet Sheet1.

Right-click on the chart and assign it this marcro:

Code:
Sub MyChart_Click()
Static b As Boolean
Dim chto As ChartObject

Set chto = Worksheets("Sheet1").ChartObjects(1)

If b Then
    chto.Width = 300
    chto.Height = 200
Else
    chto.Width = 600
    chto.Height = 400
End If
b = Not b
End Sub

Now click several times on the chart and see it changing between 2 sizes.
 
Upvote 0
Hi All,
The coding below given to me by PGC works great but what would you need to add to the coding if i wanted for example for the top left hand corner of the chart to be on C10 as currently the chart only expands from where the chart is displayed.

Regards
P

This is a very simple example that you can adapt.

Let's assume that you have just 1 chart in worksheet Sheet1.

Right-click on the chart and assign it this marcro:

Code:
Sub MyChart_Click()
Static b As Boolean
Dim chto As ChartObject

Set chto = Worksheets("Sheet1").ChartObjects(1)

If b Then
    chto.Width = 300
    chto.Height = 200
Else
    chto.Width = 600
    chto.Height = 400
End If
b = Not b
End Sub

Now click several times on the chart and see it changing between 2 sizes.
 
Upvote 0
Hi

Let's say that for the small size you want the top left corner to be on F15 and for the big size on C10.

Try:

Code:
Sub MyChart_Click()
Dim chto As ChartObject
Dim rSmall As Range, rBig As Range
Static b As Boolean

Set chto = Worksheets("Sheet1").ChartObjects(1)
Set rSmall = Worksheets("Sheet1").Range("F15")
Set rBig = Worksheets("Sheet1").Range("C10")

If b Then
    chto.Width = 300
    chto.Height = 200
    chto.Left = rSmall.Left
    chto.Top = rSmall.Top
Else
    chto.Width = 600
    chto.Height = 400
    chto.Left = rBig.Left
    chto.Top = rBig.Top
End If
b = Not b
End Sub
 
Upvote 0
Thanks PGC for the below information!
I just wondered when it comes to the height and width how do i work out the sizes so the chart fits perfectly into a certain number of cells?

Hi

Let's say that for the small size you want the top left corner to be on F15 and for the big size on C10.

Try:

Code:
Sub MyChart_Click()
Dim chto As ChartObject
Dim rSmall As Range, rBig As Range
Static b As Boolean

Set chto = Worksheets("Sheet1").ChartObjects(1)
Set rSmall = Worksheets("Sheet1").Range("F15")
Set rBig = Worksheets("Sheet1").Range("C10")

If b Then
    chto.Width = 300
    chto.Height = 200
    chto.Left = rSmall.Left
    chto.Top = rSmall.Top
Else
    chto.Width = 600
    chto.Height = 400
    chto.Left = rBig.Left
    chto.Top = rBig.Top
End If
b = Not b
End Sub
 
Upvote 0
Hi

You can use the size information of the range object:

Code:
Sub MyChart_Click()
Dim ws As Worksheet
Dim chto As ChartObject
Dim rSmall As Range, rBig As Range
Static b As Boolean

Set chto = Worksheets("Sheet1").ChartObjects(1)
Set rSmall = Worksheets("Sheet1").Range("E10:J20")
Set rBig = Worksheets("Sheet1").Range("C10:M25")

If b Then
    chto.Width = rSmall.Width
    chto.Height = rSmall.Height
    chto.Left = rSmall.Left
    chto.Top = rSmall.Top
Else
    chto.Width = rBig.Width
    chto.Height = rBig.Height
    chto.Left = rBig.Left
    chto.Top = rBig.Top
End If
b = Not b
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,376
Messages
6,119,179
Members
448,871
Latest member
hengshankouniuniu

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