Dear Expert,

Please look at this code what is wrong with it I'm not an expert in VBA but
would need some of your knowledge in this matter
I want to put together a formula that takes say a 6/49 lotto and point out
say I want to find the most occurring triples, it finds them and show how
many times each occurs. Thanks in advance. my code wont work it says error
9. what I'm I doing wrong

Sub countTriplets()
Const ntbl As Long = 18424    ' combin(49,3)
Dim tbl(1 To ntbl, 1 To 2) As Long
Dim v As Variant
Dim nv As Long, i As Long, j As Long
Dim n1 As Long, n2 As Long, n3 As Long
Dim k As Long, k1 As Long, k2 As Long
Dim m As Long, lo As Long, hi As Long
Dim r As Long
Dim s As String
Dim st As Single, et As Single

' requires sheets "data2" and "triplets".
'
' "data" contains historical drawings in columns C:H
' starting in row 1.  for each drawing, numbers must
' be in ascending order from left to right.
'
' "triplets" will contain results in columns A:D.

st = Timer
Sheets("data2").Activate
v = Range("c1", Range("h1").End(xlDown))
nv = UBound(v, 1)

' build triplets lookup table
i = 0
For n1 = 1 To 47
      k1 = n1 * 1000000
      For n2 = n1 + 1 To 48
          k2 = n2 * 10000
          For n3 = n2 + 1 To 49
                  i = i + 1
                  k = k1 + k2 + n3
                  tbl(i, 1) = k
Next n3, n2, n1
DoEvents

' determine triplets
For i = 1 To nv
      For n1 = 1 To 4
          k1 = v(i, n1) * 1000000
          For n2 = n1 + 1 To 5
              k2 = v(i, n2) * 10000
              For n3 = n2 + 1 To 6
                      k = k1 + k2 + v(i, n3)
                      ' binary search of tbl
                      lo = 1: hi = ntbl
                      Do
                          m = Int((lo + hi) / 2)
                          If k = tbl(m, 1) Then Exit Do
                          If k < tbl(m, 1) Then hi = m - 1 _
                          Else lo = m + 1
                      Loop
                      tbl(m, 2) = tbl(m, 2) + 1
      Next n3, n2, n1
      If i Mod 100 = 0 Then DoEvents
Next i

' write triplets
With Application
      .ScreenUpdating = False
      .Calculation = xlCalculationManual
End With
Sheets("triplets").Activate
Columns("a:d").Clear
Range("a1") = "count"
Range("b1") = "triplets..."
r = 1
For i = 1 To ntbl
      If tbl(i, 2) <> 0 Then
          r = r + 1
          Cells(r, 1) = tbl(i, 2)
          k = tbl(i, 1)
          For j = 5 To 2 Step -1
              Cells(r, j) = k Mod 100
              k = Int(k / 100)
          Next
      End If
Next
Columns("a:d").AutoFit
s = Format(ntbl - r + 1, "#,##0") & " of " & Format(ntbl, "#,##0")
Cells(r + 1, 1) = 0
Cells(r + 1, 2) = s
et = Timer
With Application
      .Calculation = xlCalculationAutomatic
      .ScreenUpdating = True
End With
MsgBox s & " = 0" & _
      vbNewLine & Format(et - st, "0.000000") & " sec"
End Sub


On Mon, Jun 9, 2014 at 7:28 PM, Vaibhav Joshi <v...@vabs.in> wrote:

> Hi
>
> change line to
>
> LastRow = Workbooks("Quantum 
> R-Creator.xlsm").Worksheets("Dump").Range("E1048576").End(xlUp).Row
> + 1
>
> If you include workbook name then you need to also add file extension too.
>
> Cheers!!
>
>
> On Mon, Jun 9, 2014 at 11:07 PM, Secret Shot <secrets...@gmail.com> wrote:
>
>> Dear Expert,
>>
>> I am working on a project, where i created this file to collate the data
>> from all source Excel files. It was working fine till yesterday but from
>> today when i am running collation Macro i am getting error "run time error
>> 9 subscript out of range" in below mention line
>>
>> *LastRow = Workbooks("Quantum
>> R-Creator").Worksheets("Dump").Range("E1048576").End(xlUp).Row + 1*
>>
>> I am getting this error in "Sub DFQ()" Macro in "Module 1"
>>
>> I am attaching the actual file for reference, request you to kindly help
>> me with your expertise of VBA.
>>
>> It is beyond my knowledge.
>>
>> --
>> Pankaj Pandey
>> Bhopal
>>
>> --
>> Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s
>> =TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @
>> https://www.facebook.com/discussexcel
>>
>> FORUM RULES
>>
>> 1) Use concise, accurate thread titles. Poor thread titles, like Please
>> Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice
>> will not get quick attention or may not be answered.
>> 2) Don't post a question in the thread of another member.
>> 3) Don't post questions regarding breaking or bypassing any security
>> measure.
>> 4) Acknowledge the responses you receive, good or bad.
>> 5) Jobs posting is not allowed.
>> 6) Sharing copyrighted material and their links is not allowed.
>>
>> NOTE : Don't ever post confidential data in a workbook. Forum owners and
>> members are not responsible for any loss.
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "MS EXCEL AND VBA MACROS" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to excel-macros+unsubscr...@googlegroups.com.
>> To post to this group, send email to excel-macros@googlegroups.com.
>> Visit this group at http://groups.google.com/group/excel-macros.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>  --
> Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s
> =TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @
> https://www.facebook.com/discussexcel
>
> FORUM RULES
>
> 1) Use concise, accurate thread titles. Poor thread titles, like Please
> Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice
> will not get quick attention or may not be answered.
> 2) Don't post a question in the thread of another member.
> 3) Don't post questions regarding breaking or bypassing any security
> measure.
> 4) Acknowledge the responses you receive, good or bad.
> 5) Jobs posting is not allowed.
> 6) Sharing copyrighted material and their links is not allowed.
>
> NOTE : Don't ever post confidential data in a workbook. Forum owners and
> members are not responsible for any loss.
> ---
> You received this message because you are subscribed to the Google Groups
> "MS EXCEL AND VBA MACROS" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to excel-macros+unsubscr...@googlegroups.com.
> To post to this group, send email to excel-macros@googlegroups.com.
> Visit this group at http://groups.google.com/group/excel-macros.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
https://www.facebook.com/discussexcel

FORUM RULES

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
2) Don't post a question in the thread of another member.
3) Don't post questions regarding breaking or bypassing any security measure.
4) Acknowledge the responses you receive, good or bad.
5) Jobs posting is not allowed.
6) Sharing copyrighted material and their links is not allowed.

NOTE  : Don't ever post confidential data in a workbook. Forum owners and 
members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to excel-macros+unsubscr...@googlegroups.com.
To post to this group, send email to excel-macros@googlegroups.com.
Visit this group at http://groups.google.com/group/excel-macros.
For more options, visit https://groups.google.com/d/optout.

Reply via email to