VBA Chart Positioning with a loop

jimi1987

New Member
Joined
Jul 4, 2016
Messages
15
<body id="************" style="position: absolute; top: 0px; width: 1px; height: 1px; overflow: hidden; left: -1000px;">
0down votefavorite
I have a loop creating 10 charts using Range Offset to increment 2 columns at a time.
The issue i have is the placement of each chart, currently they're stacking 10 charts on top of each other. Is there a way so each time the loop runs the chart position changes each time. Below is the code i currently have.



<tbody style="margin: 0px; padding: 0px; border: 0px;">
</tbody>
</body>
0down votefavorite
I have a loop creating 10 charts using Range Offset to increment 2 columns at a time.
The issue i have is the placement of each chart, currently they're stacking 10 charts on top of each other. Is there a way so each time the loop runs the chart position changes each time. Below is the code i currently have.


<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; white-space: inherit;">Sub charts()
'Set up the variables.
Dim rng As Range

'Use the InputBox dialog to set the range for MyFunction
Set rng = Application.InputBox("Select a range", "Obtain Range Object", Type:=8)


'Call MyFunction
ActiveCell
.Value = MyFunction(rng)
End Sub

Function MyFunction(rng As Range) As Double

For i = 1 To 20 Step 2

Endrow
= Range("A1").End(xlUp).Row - 1

Set Range1 = rng.Offset(Endrow, i + 1)

Sheets
("All team charts").Select

MyFunction
= ActiveSheet.Shapes.AddChart.Select
ActiveChart
.ChartType = xlLineMarkers
ActiveChart
.HasLegend = False
ActiveChart
.HasTitle = True
ActiveChart
.ChartTitle.Text = "Team 1"
ActiveChart
.Parent.Name = "Team 1"
ActiveChart
.SetSourceData Source:=Range1
With ActiveChart.Parent
.height = 200 ' resize
.width = 350 ' resize
.top = 20 ' reposition
.left = 20 ' reposition
End With
Next i

End Function</code>


<tbody style="margin: 0px; padding: 0px; border: 0px;">
</tbody>
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Forum statistics

Threads
1,215,831
Messages
6,127,146
Members
449,364
Latest member
AlienSx

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