montecarlo2012
Well-known Member
- Joined
- Jan 26, 2011
- Messages
- 986
- Office Version
- 2010
- Platform
- Windows
Hello.
I would like this code Read the array on sheet 3 and display the results on sheet 1
Thank you for your time.
VBA Code:
Option Explicit
Sub woren()
Worksheets("sheet3").Activate
Dim rng As Range, Dn As Range, Rw As Range
Dim n As Long
Dim Q As Variant
Dim Omax As Integer, oSub As Integer
Set rng = Range(Range("B2"), Range("B" & Rows.Count).End(xlUp)).Resize(, 3)
ReDim Ray(1 To rng.Count, 1 To 2)
With CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
For Each Rw In rng.Rows
n = n + 1
For Each Dn In Rw.Columns
If Not .exists(Dn.Value) Then
Ray(1, 1) = n - 1: Ray(1, 2) = n - 1
.Add Dn.Value, Array(Ray, 1)
Else
Q = .Item(Dn.Value)
Q(1) = Q(1) + 1
oSub = IIf(Q(1) > 2, 1, 2)
Q(0)(Q(1), 1) = n
Q(0)(Q(1), 2) = n - Q(0)(Q(1) - 1, 1) - oSub
Omax = Application.Max(Omax, Q(1))
.Item(Dn.Value) = Q
End If
Next Dn
Next Rw
Dim K As Variant
Dim R As Long
Dim c As Long
c = 1
For Each K In .keys
c = c + 1
Cells(c, 7) = K '' Column G, with the list of numbers you want to report
Cells(c, 12).Font.Bold = True 'location for the results
For R = 1 To .Item(K)(1)
Cells(c, 12 + R) = .Item(K)(0)(R, 2)
Next R
Next K
Sheet1.Range("G2").Resize(.Count, Omax + 3).Sort Range("G2"), xlAscending 'the bin from 1 to end
Call RwData(Range("M2").Resize(.Count), Omax) ' this is the skip report starter or column 13
End With
End Sub
Sub RwData(rng As Range, col As Integer)
Range("J1").Value = "AVERAGE"
Range("K1").Value = "DEVIATION"
Range("N1").Value = "ABSENT"
Range("M1").Value = "DELAY"
Range("I1").Value = "OUTAVG"
Dim Dn As Range
For Each Dn In rng
With Application
Dn.Offset(, -3) = Round((.Average(Dn.Resize(, .CountA(Dn.Resize(, col))))), 1) 'this is colum J ==============or 10 [or -3 from 13]
Dn.Offset(, -4) = Round((Abs(Dn / .Average(Dn.Resize(, .CountA(Dn.Resize(, col)))))), 1)
Dn.Offset(, -2) = Fix(Abs(Dn - .Average(Dn.Resize(, .CountA(Dn.Resize(, col)))))) 'column K or -2 from 13
Dn.Offset(, -5) = Dn - Cells(2, 10).Value
End With
Next Dn
End Sub
Thank you for your time.