ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Moving Charts (https://www.excelbanter.com/excel-programming/431997-moving-charts.html)

Ken

Moving Charts
 
I have a set of macros that loop through all my worksheets and move my charts.

I have found that the charts do not always move. Do I need to place some
type refresh after each move?

Thank you.

Peter T

Moving Charts
 
Moving charts should be pretty straightforward with no need to 'Refresh'.
More likely your code is not doing what you think it is.

Regards,
Peter T

"Ken" wrote in message
...
I have a set of macros that loop through all my worksheets and move my
charts.

I have found that the charts do not always move. Do I need to place some
type refresh after each move?

Thank you.




Ken

Moving Charts
 
Hi Peter,

Here is the code I am using:

Set objChart = oSheet.ChartObjects(PlotName)

objChart.Activate

With objChart
.Top = PlotTop
.Left = PlotLeft
.Width = PlotWidth
.Height = PlotHeight
End With

I calculate PlotTop using:

PlotTop = oSheet.Rows(ChartTopRow).Top

oSheet is set to the current worksheet (worksheet object) and ChartTopRow is
set to 44. The plot is moving to the top of row 57.

Ken


"Peter T" wrote:

Moving charts should be pretty straightforward with no need to 'Refresh'.
More likely your code is not doing what you think it is.

Regards,
Peter T

"Ken" wrote in message
...
I have a set of macros that loop through all my worksheets and move my
charts.

I have found that the charts do not always move. Do I need to place some
type refresh after each move?

Thank you.





Peter T

Moving Charts
 
From what you've described your code looks OK but we can't see your actual
variables, so must be something else only you can see. Eg, what's
ChartTopRow

Sub test()
Dim lt As Double
Dim tp As Double
Dim chtObj As ChartObject

lt = ActiveSheet.Columns(2).Left
tp = ActiveSheet.Rows(44).Top

Set chtObj = ActiveSheet.ChartObjects.Add(0, 0, 200, 100)

With chtObj
.Left = lt
.Top = tp
End With
Application.Goto Range("a40"), True

End Sub

In passing, no need to Activate your chart

Regards,
Peter T

"Ken" wrote in message
...
Hi Peter,

Here is the code I am using:

Set objChart = oSheet.ChartObjects(PlotName)

objChart.Activate

With objChart
.Top = PlotTop
.Left = PlotLeft
.Width = PlotWidth
.Height = PlotHeight
End With

I calculate PlotTop using:

PlotTop = oSheet.Rows(ChartTopRow).Top

oSheet is set to the current worksheet (worksheet object) and ChartTopRow
is
set to 44. The plot is moving to the top of row 57.

Ken


"Peter T" wrote:

Moving charts should be pretty straightforward with no need to 'Refresh'.
More likely your code is not doing what you think it is.

Regards,
Peter T

"Ken" wrote in message
...
I have a set of macros that loop through all my worksheets and move my
charts.

I have found that the charts do not always move. Do I need to place
some
type refresh after each move?

Thank you.







Ken

Moving Charts
 
Peter,

ChartTopRow was a variable I passed into a move and position funciton. I
found the problem in that I was passing in the ChartTopRow byref and it
should have been byval as I was modifying it in the code.

Thanks for the help.


"Peter T" wrote:

From what you've described your code looks OK but we can't see your actual
variables, so must be something else only you can see. Eg, what's
ChartTopRow

Sub test()
Dim lt As Double
Dim tp As Double
Dim chtObj As ChartObject

lt = ActiveSheet.Columns(2).Left
tp = ActiveSheet.Rows(44).Top

Set chtObj = ActiveSheet.ChartObjects.Add(0, 0, 200, 100)

With chtObj
.Left = lt
.Top = tp
End With
Application.Goto Range("a40"), True

End Sub

In passing, no need to Activate your chart

Regards,
Peter T

"Ken" wrote in message
...
Hi Peter,

Here is the code I am using:

Set objChart = oSheet.ChartObjects(PlotName)

objChart.Activate

With objChart
.Top = PlotTop
.Left = PlotLeft
.Width = PlotWidth
.Height = PlotHeight
End With

I calculate PlotTop using:

PlotTop = oSheet.Rows(ChartTopRow).Top

oSheet is set to the current worksheet (worksheet object) and ChartTopRow
is
set to 44. The plot is moving to the top of row 57.

Ken


"Peter T" wrote:

Moving charts should be pretty straightforward with no need to 'Refresh'.
More likely your code is not doing what you think it is.

Regards,
Peter T

"Ken" wrote in message
...
I have a set of macros that loop through all my worksheets and move my
charts.

I have found that the charts do not always move. Do I need to place
some
type refresh after each move?

Thank you.








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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com