montecarlo2012
Well-known Member
- Joined
- Jan 26, 2011
- Messages
- 984
- Office Version
- 2010
- Platform
- Windows
Hi, I will try to explain in different way.
There are an dynamic array at B2:F10000 to read and a column Z2:Z37 with a series from 1 to 36
Read each number of each row and find how many rows are between the same value
Example
If value 10 is found in the row B4:F4 at D4 then on column AA5 will show the count 4 beside Z5 row
After the value 10 is again in another row in this time is at B12:F12 at C12 so counting from row B4 until B12:F12 row there are 7 rows down, now AA6 will show the value 7
The important point here is to know how many Rows there are between the same value
And it Not about how many cells.
The code should work as follows:
Loop through each row in the data range.(B2:F10000)
For each row, find the value in column Z2:Z37
calculate the difference between the current row and the previous row with the same value
I am looking to count the number of rows between occurrences of a value in column Z, and display the result in column AA for each occurrence of the value at the array
the bad part of the code I am loading now is that work only for 200 rows,
if I upload all the 10000 rows then take one hour running and must of the time at the end give me error
that why I came here guys looking for help Please.
here is the code
the dent may be is better
thanks.
There are an dynamic array at B2:F10000 to read and a column Z2:Z37 with a series from 1 to 36
Read each number of each row and find how many rows are between the same value
Example
If value 10 is found in the row B4:F4 at D4 then on column AA5 will show the count 4 beside Z5 row
After the value 10 is again in another row in this time is at B12:F12 at C12 so counting from row B4 until B12:F12 row there are 7 rows down, now AA6 will show the value 7
The important point here is to know how many Rows there are between the same value
And it Not about how many cells.
The code should work as follows:
Loop through each row in the data range.(B2:F10000)
For each row, find the value in column Z2:Z37
calculate the difference between the current row and the previous row with the same value
I am looking to count the number of rows between occurrences of a value in column Z, and display the result in column AA for each occurrence of the value at the array
the bad part of the code I am loading now is that work only for 200 rows,
if I upload all the 10000 rows then take one hour running and must of the time at the end give me error
that why I came here guys looking for help Please.
here is the code
VBA Code:
Sub Total_games_skips()
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
Range("G2:BB100").ClearContents
Set rng = Range(Range("B2"), Range("B" & Rows.count).End(xlUp)).Resize(, 5) 'dynamic array of 5 columns ("B2:F")
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
Range("G2").Resize(.count, Omax + 5).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 = "SKIP"
Range("M1").value = "OUT"
Dim Dn As Range
For Each Dn In rng
With Application
'Dn.Offset(, -3) = Fix(.Average(Dn.Resize(, .CountA(Dn.Resize(, col))))) 'this is colum J or 10 [or -3 from 13]
Dn.Offset(, -3) = Round((.Average(Dn.Resize(, .CountA(Dn.Resize(, col))))), 1)
If Dn.Offset(, -3) = Fix(Abs(Dn - .Average(Dn.Resize(, .CountA(Dn.Resize(, col)))))) Then
Dn.Offset(, -1) = "yes"
End If
If Dn.Offset(, -2).Value2 = Fix(Abs(Dn - .Average(Dn.Resize(, .CountA(Dn.Resize(, col)))))) Then
Dn.Offset(, -4) = "yes"
End If
Dn.Offset(, -2) = Fix(Abs(Dn - .Average(Dn.Resize(, .CountA(Dn.Resize(, col)))))) 'column K or -2 from 13
End With
Next Dn
End Sub
thanks.