Macro to set Chart Size to a Range with variables

jdog79

New Member
Joined
Apr 6, 2008
Messages
11
Hello, I'm trying to get my graph into a specified range. I'm trying to make the range for the graph dependent on the dimensions of the table next to it (for uniformity and neatness). I'm getting an error on how I defined my range. Current values of F and T are 0 and 6 respectively. Also, I found this code online that uses a loop, how do I set the chart dimensions for the active chart only?

Code:
Set rng = ActiveSheet.Range(Range("A13").Offset(F, 0), Range("A14").Offest(8 + T, 7))
    For x = 1 To ActiveSheet.Shapes.Count
        If ActiveSheet.Shapes(x).Type = msoChart Then
            ActiveSheet.Shapes(x).Width = rng.Width
            ActiveSheet.Shapes(x).Height = rng.Height
            ActiveSheet.Shapes(x).Top = rng.Top
            ActiveSheet.Shapes(x).Left = rng.Left
        End If
    Next
Also here: http://www.ozgrid.com/forum/showthread.php?p=430537#
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
well it's amazing what a fresh pair of eyeballs can do for you! They typo fixes my issue with the range, however I'm still unsure how how set the dimensions for just the active chart, without looping through all charts.
 
Upvote 0
Untested...

Code:
with activechart.parent
.left=rng.left
.top=rng.top
    '...whatever else you want to set
    end with
well it's amazing what a fresh pair of eyeballs can do for you! They typo fixes my issue with the range, however I'm still unsure how how set the dimensions for just the active chart, without looping through all charts.
 
Upvote 0
This worked:
Rich (BB code):
If Not ActiveChart Is Nothing Then 
    With ActiveChart.Parent 
        .Width = rng.Width 
        .Height = rng.Height 
        .Top = rng.Top 
        .Left = rng.Left 
    End With 
End If

glad you liked all my typos, I think VBA has cooked my brain!:laugh:
 
Upvote 0
Those kinds of errors should not happen. Enable and use Intellisense (in the VB Editor, select Tools | Options... | Editor tab | check 'Auto List Members' and...heck, just check every checkbox in that section).

This worked:
{snip}

glad you liked all my typos, I think VBA has cooked my brain!:laugh:
 
Upvote 0

Forum statistics

Threads
1,224,585
Messages
6,179,705
Members
452,939
Latest member
WCrawford

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