Creating Multiple Charts and Moving them

Bajan

New Member
Joined
Feb 21, 2016
Messages
36
I have two tasks that I need some help with relating to creating and moving charts.

1. I have created a chart which gets its source data from range "A3:C26". I now want to create 12 additional charts which get their data from across 4 columns each. So the next chart will use range "D3:G26", the next "H3:K26", the next "L3:O26"...and so on, with the last from "AV3:AY26". Can you please help me with the code to put this in a For Loop or some other method.

2. I then want to move these 13 charts from wsMC worksheet and place them one under each other on a worksheet called POTOC-Charts.

Can you please help me with the two tasks.

Here is what I have done so far:


Private Sub OSMCharts_Click()
Dim wsMC As Worksheet, wsDoc As Worksheet
Dim myChtObj As ChartObject
Dim rngChtData As Range
Dim rngChtXVal As Range
Dim iColumn As Long
Dim Chrtname As String, lookfor As String, myMonthYear As String
Dim nbrMonth As Integer, i As Integer

Set wsDoc = ThisWorkbook.Worksheets("Daily OSM Checklist")
Set wsMC = ThisWorkbook.Worksheets("Monthly Charts")

wsMC.Activate

'initialize variables
nbrMonth = Month(wsDoc.Range("B3"))
myMonthYear = MonthName(nbrMonth, True) & " - " & Year(wsDoc.Range("B3"))

Chrtname = wsMC.Range("A2") & " for " & myMonthYear

' make sure a range is selected
If TypeName(Selection) <> "Range" Then Exit Sub

' define chart data
Set rngChtData = wsMC.Range("A3:C26")
' define chart's X values
With rngChtData
Set rngChtXVal = .Columns(1).Offset(1).Resize(.Rows.Count - 1)
End With
' add the chart
Set myChtObj = ActiveSheet.ChartObjects.Add _
(Left:=40, Width:=900, Top:=350, Height:=225)

With myChtObj.Chart
' make an XY chart
.ChartType = xlColumnClustered

'chart name
.HasTitle = True
.ChartTitle.Text = Chrtname
.ChartTitle.Font.Size = 12
.ChartTitle.Font.Color = vbBlack

'X axis name
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Day"

'y-axis name
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Hour"
.ChartArea.Format.Fill.ForeColor.RGB = RGB(0, 255, 0)

With wsMC.ChartObjects(1).Chart.PlotArea.Format.Fill
.Visible = msoFalse
.Visible = msoTrue
.TwoColorGradient msoGradientHorizontal, 1
.ForeColor.RGB = RGB(255, 255, 0)
.BackColor.RGB = RGB(0, 176, 240)
End With

.HasDataTable = True
.DataTable.HasBorderOutline = True
.HasLegend = False

' remove extra series
Do Until .SeriesCollection.Count = 0
.SeriesCollection(1).Delete
Loop
' add series from selected range, column by column
For iColumn = 2 To rngChtData.Columns.Count
With .SeriesCollection.NewSeries
.Values = rngChtXVal.Offset(, iColumn - 1)
.XValues = rngChtXVal
.Name = rngChtData(1, iColumn)
End With
Next

With .SeriesCollection(1)
.Name = "Online Availability"
.Format.Fill.ForeColor.RGB = RGB(0, 0, 255)
End With
With .SeriesCollection(2)
.ChartType = xlLine
.MarkerStyle = xlMarkerStyleDiamond
.Format.Fill.ForeColor.RGB = RGB(0, 255, 0)
End With

End With
End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
I struggled with this for the entire day after getting no response and was finally able to solve it. So in the event anyone was going to respond, there is no need to do so. Thanks.
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,126
Members
452,381
Latest member
Nova88

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