krishnan v
New Member
- Joined
- Dec 26, 2019
- Messages
- 1
- Office Version
- 365
- Platform
- Windows
I am new and am going step by step. I have 5 columns with the first column always being the x axis and the others will be the y axis. I will end up with 4 XY scatter charts ultimately.
Before i moved over to looping, i tried using range values and came up with the following code, however while plotting the chart, it tends to add all the series to the same chart and not just one. How do I get over this.
Second is how do I proceed to looping, ie. get 4 charts with the same X axis and different y axis
DOS | flow | temperature | pressure | level |
m3/hr | deg C | bar | % | |
1.00 | 100 | 60 | 14.7 | 51 |
2.00 | 200 | 50 | 14.7 | 51 |
3.00 | 1400 | 60 | 14.7 | 50 |
4.00 | 1200 | 60 | 14.7 | 53 |
5.00 | 5500 | 50 | 14.7 | 55 |
6.00 | 230 | 60 | 1.8 | 51 |
7.00 | 230 | 50 | 14.7 | 52 |
8.00 | 230 | 60 | 14.8 | 54 |
9.00 | 222 | 60 | 14.7 | 56 |
10.00 | 222 | 50 | 14.7 | 55 |
11.00 | 222 | 60 | 14.7 | 53 |
12.00 | 222 | 50 | 14.7 | 52 |
13.00 | 555 | 60 | 14.7 | 51 |
14.00 | 222 | 60 | 14.7 | 50 |
Second is how do I proceed to looping, ie. get 4 charts with the same X axis and different y axis
VBA Code:
Sub krishcharttrial()
' defining the integers for iterations
Dim a As Integer
Dim b As Integer
Dim i As String
Dim j As String
Dim x As String
Dim y As String
Dim z As String
x = Cells(1, 4)
y = Cells(2, 4)
z = Cells(1, 1)
i = Range(Cells(3, 1), Cells(16, 1)).Address
j = Range(Cells(3, 4), Cells(16, 4)).Address
ActiveSheet.Shapes.AddChart.Select
ActiveChart.charttype = xlXYScatter
ActiveChart.SetSourceData Source:=Range(i, j)
' chart title
ActiveChart.HasTitle = True
ActiveChart.ChartTitle.Text = x & " vs " & y
ActiveChart.Legend.Position = xlBottom
ActiveChart.Axes(xlValue).TickLabels.Font.Bold = True
ActiveChart.Axes(xlCategory).TickLabels.Font.Bold = True
ActiveChart.Axes (xlValue)
'Add X-axis title
ActiveChart.Axes(xlCategory, xlPrimary).HasTitle = True
ActiveChart.Axes(xlCategory, xlPrimary).AxisTitle.Text = z
'Add y-axis title
ActiveChart.Axes(xlValue, xlPrimary).HasTitle = True
ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Text = y
'Add Major Gridlines
ActiveChart.SetElement (msoElementPrimaryValueGridLinesMajor)
ActiveChart.Location where:=xlLocationAsNewSheet, Name:=x
ActiveSheet.Move After:=Sheets(Sheets.Count)
Sheets("sheet1").Select
End Sub
Last edited by a moderator: