Hi, not sure where exactly should I address this problem since it is both charts AND VBA...
I am working on a project where I calculate probability distributions of certain data you can see in this file: (the codes are here too) https://docs.google.com/file/d/0Bwjh...it?usp=sharing
1. I calculated the intervals with the frequencies for each interval data.
2. I cumulated them and placed into the array results2
3. I display each of them in the SAME graphic.. but HERE I get a problem... Sometimes the code works, and sometimes I get a With End block ... sometimes even only ONE curve displays.. it's really annoying. Could anyone please help me with that?
ALL is supposed to be ont the same graph*
My chart VBA code:
The sub it corresponds to is:
I am working on a project where I calculate probability distributions of certain data you can see in this file: (the codes are here too) https://docs.google.com/file/d/0Bwjh...it?usp=sharing
1. I calculated the intervals with the frequencies for each interval data.
2. I cumulated them and placed into the array results2
3. I display each of them in the SAME graphic.. but HERE I get a problem... Sometimes the code works, and sometimes I get a With End block ... sometimes even only ONE curve displays.. it's really annoying. Could anyone please help me with that?
ALL is supposed to be ont the same graph*
My chart VBA code:
Code:
Sub ChartNew2(result2 As Variant)
Dim i As Integer
ReDim result2(1 To 20, 1 To 1)
Charts.Add
For i = LBound(result2, 1) To UBound(result2, 1)
result2(i, 1) = result2
Next i
ActiveChart.ChartType = xlXYScatterSmoothNoMarkers
ActiveChart.Location Where:=xlLocationAsObject, Name:="Chart 1"
With ActiveChart
.HasTitle = True
.Axes(xlValue, xlPrimary).HasTitle = True
End With
With ActiveChart.Axes(xlValue)
.HasMajorGridlines = True
End With
ActiveChart.HasLegend = False
ActiveChart.PlotArea.Select
Selection.Interior.ColorIndex = xlAutomatic
ActiveChart.Axes(xlValue).Select
With ActiveChart.Axes(xlValue)
.MaximumScale = 1
End With
End Sub
Code:
Option Explicit
Option Base 1
Sub IntervallesFrequences()
Dim cMin As Double
Dim cMax As Double
Dim lDer As Long
Dim NoIntervals As Long
Dim plaga() As Variant
Dim i As Long
Dim J As Long
Dim EnsembleActions As Range
Dim dest As Range
Dim A As Integer
Dim B As Integer
Dim rColumn() As Variant
Dim result() As Variant
ReDim result(1 To 20)
ReDim result2(1 To 20)
Dim nb_Actions As Long
Dim nb_Cours As Long
Dim Action As Range
Dim idx As Long
nb_Actions = Worksheets("Actions").Cells(1, Columns.Count).End(xlToLeft).Column - 1
nb_Cours = Worksheets("Actions").Cells(Rows.Count, 2).End(xlUp).Row - 1
NoIntervals = 20
With Worksheets("Actions")
Set EnsembleActions = .Range(.Cells(2, 2), .Cells(.Rows.Count, nb_Actions + 1).End(xlUp))
End With
For Each Action In EnsembleActions.Columns
' Supposed to fill the array with values from the cells in EACH column. MUST be an array
plaga = Action.Value
Call tri1(plaga)
cMin = WorksheetFunction.Min(plaga)
cMax = WorksheetFunction.Max(plaga)
Dim longInter As Double
longInter = (cMax - cMin) / NoIntervals
ReDim plaga2(1 To NoIntervals) As Long
ReDim arrIntervals(1 To NoIntervals)
Dim pla As Variant
Dim lCom As Long
Dim res As Variant
For i = 1 To NoIntervals
arrIntervals(i) = cMax - ((i - 1) * longInter)
Next i
For Each pla In plaga
res = Application.Match(pla, arrIntervals, -1)
If Not IsError(res) Then
plaga2(res) = plaga2(res) + 1
End If
Next pla
'For J = 20 To 1 Step -1
'Worksheets("Sheet1").Cells(1, 2).Offset(20 - J) = arrintervals(J)
'Worksheets("Sheet1").Cells(1, 3).Offset(20 - J) = plaga2(J)
'Next J
result(1) = plaga2(1)
For B = 2 To 20
result(B) = (plaga2(B) + result(B - 1))
Next B
For A = 1 To 20
result2(A) = WorksheetFunction.Round((result(A) / nb_Cours) * 100, 2) & " %"
Next A
'MsgBox "THE CDF IS as follows: " & vbCrLf & vbCrLf & Join(result2, vbCrLf), 0, "Debug"
Set dest = Worksheets("Distributions").Range("A3").Offset(, idx)
dest.Resize(20, 1).Value = Application.Transpose(result2)
Call ChartNew2(result2)
idx = idx + 1
Next Action
End Sub