Generate multiple Charts

GoldSugar

New Member
Joined
Mar 25, 2014
Messages
5
Hello,

I'm trying to generate multiples charts using VBA (2 per lines)
I'm only able to generate always at the same place

Here is my code:

VBA Code:
Sub generate_chart()

Dim chrt As ChartObject

Sheets("Main").Activate

For i = 2 To 5

Set chrt = Sheets("Main").ChartObjects.Add(Left:=10, Width:=270, Top:=10, Height:=210)
chrt.Chart.SetSourceData Source:=Sheets("Calc").Range("A1:T1,A" & i & ":T" & i)
chrt.Chart.ChartType = xlLine

Next i

End Sub

Thanks for your help :)
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Here is what I have
1674820772031.png


here is what i expect

1674820810746.png
 
Upvote 0
VBA Code:
Sub CreateCharts()

  Dim range As range
  Dim i As Integer

  'Define range to loop through
  Set range = ActiveSheet.range("A1:C10")
  For i = 1 To range.Rows.Count
      'If value in Column C is not empty
      If Not IsEmpty(range.Cells(i, 3).Value) Then
          'Create chart with Columns A and B
          ActiveSheet.Shapes.AddChart2(201, xlColumnClustered).Select
          ActiveChart.SetSourceData Source:=range.Offset(i - 1, 0).Resize(2, 3)
          'Offset chart position based on row number
          ActiveChart.Parent.Top = i * 200
          ActiveChart.Parent.Left = i * 200
      End If
  Next i

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,819
Messages
6,121,741
Members
449,050
Latest member
excelknuckles

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