J
JP
I have a macro that sets the input data for several charts. I have a probelm
becuase it works for the first chart but then nothing happens. Let me guide
you through my code:
In one sub I give info on which tyoes of data that are to be used when
finding the input data for the charts.
If index = 0 Then
varWorksheetInfoArray(0) = "Avkdata"
varWorksheetInfoArray(1) = "Date"
call ChartMaker(varWorksheetInfoArray)
End if
if index =1....etc
Private Sub chartMaker(ByRef varWorksheetInfoArray() As Variant)
Dim i, j As Integer
Dim rng1, rng2, rng3, rng4, rng5, rng6, rng7 As Range
Set rng1 =
Worksheets(varWorksheetInfoArray(0)).Cells.Find(varWorksheetInfoArray(1),
LookIn:=xlValues)
Set rng2 =
Worksheets(varWorksheetInfoArray(0)).Cells.Find(varWorksheetInfoArray(2),
LookIn:=xlValues)
etc.
I then make some loops to find start and end values for the input data.
I then proceed to set the actual data for the chart:
Sheets("Rapport").Select
ActiveSheet.ChartObjects(varWorksheetInfoArray(10)).Activate
ActiveChart.Axes(xlCategory).Select
With ActiveChart
..SeriesCollection(1).XValues =
Sheets(varWorksheetInfoArray(0)).Range(rng1.Offset(i, 0).Address & ":" &
rng1.Offset(j, 0).Address)
End With
'sätter x-axel
With ActiveChart
If Not rng2 Is Nothing Then
..SeriesCollection(1).Values =
Sheets(varWorksheetInfoArray(0)).Range(rng2.Offset(i, 0).Address & ":" &
rng2.Offset(j, 0).Address)
Else: End If
If Not rng3 Is Nothing Then
..SeriesCollection(2).Values =
Sheets(varWorksheetInfoArray(0)).Range(rng3.Offset(i, 0).Address & ":" &
rng3.Offset(j, 0).Address)
Else: End If
Now this works fine the first loop in my program i.e. when index = 0. I
think that the problem is in the:
If Not rng3 Is Nothing Then
........
But I cannot figure out what it is. I am very bad at vba so if you have any
idea and you are able to point in any direction I would be very greatful!!
Thank you all for invaluable assistance!
_________________
becuase it works for the first chart but then nothing happens. Let me guide
you through my code:
In one sub I give info on which tyoes of data that are to be used when
finding the input data for the charts.
If index = 0 Then
varWorksheetInfoArray(0) = "Avkdata"
varWorksheetInfoArray(1) = "Date"
call ChartMaker(varWorksheetInfoArray)
End if
if index =1....etc
Private Sub chartMaker(ByRef varWorksheetInfoArray() As Variant)
Dim i, j As Integer
Dim rng1, rng2, rng3, rng4, rng5, rng6, rng7 As Range
Set rng1 =
Worksheets(varWorksheetInfoArray(0)).Cells.Find(varWorksheetInfoArray(1),
LookIn:=xlValues)
Set rng2 =
Worksheets(varWorksheetInfoArray(0)).Cells.Find(varWorksheetInfoArray(2),
LookIn:=xlValues)
etc.
I then make some loops to find start and end values for the input data.
I then proceed to set the actual data for the chart:
Sheets("Rapport").Select
ActiveSheet.ChartObjects(varWorksheetInfoArray(10)).Activate
ActiveChart.Axes(xlCategory).Select
With ActiveChart
..SeriesCollection(1).XValues =
Sheets(varWorksheetInfoArray(0)).Range(rng1.Offset(i, 0).Address & ":" &
rng1.Offset(j, 0).Address)
End With
'sätter x-axel
With ActiveChart
If Not rng2 Is Nothing Then
..SeriesCollection(1).Values =
Sheets(varWorksheetInfoArray(0)).Range(rng2.Offset(i, 0).Address & ":" &
rng2.Offset(j, 0).Address)
Else: End If
If Not rng3 Is Nothing Then
..SeriesCollection(2).Values =
Sheets(varWorksheetInfoArray(0)).Range(rng3.Offset(i, 0).Address & ":" &
rng3.Offset(j, 0).Address)
Else: End If
Now this works fine the first loop in my program i.e. when index = 0. I
think that the problem is in the:
If Not rng3 Is Nothing Then
........
But I cannot figure out what it is. I am very bad at vba so if you have any
idea and you are able to point in any direction I would be very greatful!!
Thank you all for invaluable assistance!
_________________