cellMatrix.net

Spreadsheet Modeling and Related Topics

Align Charts to Worksheet Grid Post 2

As a follow-up to Align Charts to Worksheet Grid Post 1, the following procedure assigns a name, sizes, and aligns all of the embedded charts on a single worksheet. The key to the procedure is the location (range address) of the cell at the top left side of the chart.

Sub AlignCharts()

    Dim Cht As ChartObject

    For Each Cht In ActiveSheet.ChartObjects
        'Note: Naming the chart is optional.
        Cht.Parent.Name = Cht.TopLeftCell.Offset(-1, 0).Value
        Cht.Top = Cht.TopLeftCell.Top
        Cht.Left = Cht.TopLeftCell.Left
        Cht.Height = 114.75
        Cht.Width = 192
    Next Cht

End Sub

Given four embedded charts on a single sheet, the output looks like this:

image

Each chart is assigned the name of the value in the cell just above the top left cell. Each chart is aligned to the top-left cell and sized as per the height and width assignments.

With this procedure you don't have to worry about naming the charts first or building loops to place them. Just create a new chart, move it to the top-left cell location of your choice, add a name for the chart above the top-left cell, and run the macro.


Posted on Saturday, December 08, 2007 | Comments (0) | Permalink

Comment Entry Form

User Information

Name: (Required)

E-Mail Address: (Optional)

Location: (Optional)

Web Site Address: (Optional)

Comment Formatting Reference
Add VBA Code:
<pre>some code here</pre>
Linking:
[url]http://www.example.com/[/url]
[url=http://www.example.com/]my site[/url]
Text Formatting
[size=4]Some larger text[/size]
[color=green]Some green text[/color]
[b]Some bold text[/b]
[i]Some italic text[/i]
Enter Comment Below

Personalization Options
Remember my personal information
Notify me of follow-up comments?

Next entry: Formatting of Reports Before Excel File Distribution

Previous entry: Add Labels to Chart Data Points

<< Back to main

Statistics

  • Total Entries - 136
  • Current Viewers - 16

Categories

Entries by Day

Sep - 2010
S M T W T F S
29 30 31 1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 1 2

Recent Comments

Syndicate