Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Placing charts

I am writing a macro the generates charts onto a new worksheet. I want to be
able to decide in the code where I want to place the charts. How do you do
this? When recording amcro I cannot make the placement exact so how do you
write the proper code? Please help me!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Placing charts

Hi
The chart you add is contained within a ChartObject, which is the
Parent object of the Chart, and you need to set the position of that.
So
Set myChart = Charts.Add
With myChart.Parent
.Top = Range("C2").Top
.Left = Range("C2").Left
end with

will put the top left corner of the chart in the top left corner of C2.

regards
Paul

Fabrizio wrote:
I am writing a macro the generates charts onto a new worksheet. I want to be
able to decide in the code where I want to place the charts. How do you do
this? When recording amcro I cannot make the placement exact so how do you
write the proper code? Please help me!


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Placing charts

Oops
This will add as a chart sheet, not embed in a sheet. If you have an
existing chart on a sheet called "DataChart" you could do

Set myChart = Chartobjects("DataChart")

then set its position as before.
If the chart does not already exist you will have to do,

Set myChart = Charts.Add
Set myChart = myChart.Location(Whe=xlLocationasObject,
Name:="myWorkSheet")

where myWorkSheet is the name of the sheet you want the chart on.

regards
Paul

wrote:
Hi
The chart you add is contained within a ChartObject, which is the
Parent object of the Chart, and you need to set the position of that.
So
Set myChart = Charts.Add
With myChart.Parent
.Top = Range("C2").Top
.Left = Range("C2").Left
end with

will put the top left corner of the chart in the top left corner of C2.

regards
Paul

Fabrizio wrote:
I am writing a macro the generates charts onto a new worksheet. I want to be
able to decide in the code where I want to place the charts. How do you do
this? When recording amcro I cannot make the placement exact so how do you
write the proper code? Please help me!


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Placing charts

Thank you very much for your help. I am however a beginner at VB so I cannot
use your code directly. When using the code (that you gave me):

Set myChart = Charts.Add
With myChart.Parent
.Top = Range("C2").Top
.Left = Range("C2").Left
End With

I get error that says that the method range failed in the object '_Global'.
I do not know what that means or how to solve it. The code for the sub that
creats the chart begins with:

Private Sub chartMaker(rng1, rng2, rng3 As Range, ByVal s, x As String,
index As Integer)

When using your other code that you gave me I get error since method or
object not declared. Please help me! I just want to solve the simple problems
that I described. But I cannot use macros since then I wont be able to use
the code the way I want.

" skrev:

Hi
The chart you add is contained within a ChartObject, which is the
Parent object of the Chart, and you need to set the position of that.
So
Set myChart = Charts.Add
With myChart.Parent
.Top = Range("C2").Top
.Left = Range("C2").Left
end with

will put the top left corner of the chart in the top left corner of C2.

regards
Paul

Fabrizio wrote:
I am writing a macro the generates charts onto a new worksheet. I want to be
able to decide in the code where I want to place the charts. How do you do
this? When recording amcro I cannot make the placement exact so how do you
write the proper code? Please help me!



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Placing shapes exactly on charts. Taylor Charts and Charting in Excel 7 August 17th 08 10:19 AM
Placing an UDF yshridhar Excel Worksheet Functions 11 August 17th 07 02:01 AM
Range reference problem placing charts Henri Excel Programming 3 April 16th 06 06:34 PM
placing.. 1st, 2nd, 3rd... fivermsg Excel Discussion (Misc queries) 1 March 14th 06 02:21 AM
placing Stig Excel Worksheet Functions 0 February 3rd 05 10:30 PM


All times are GMT +1. The time now is 12:27 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"