Joint 2 macros

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,415
Office Version
  1. 2010
Hello @Phuoc, you provide 2 VBA which are working spot-on. Please can you make 1 VBA out of 2 which get count and delay at once? Thank you.

Find Dealy MrExcel.xlsm
ABCDEFGHIJKLMNOPQ
1
2
3VBAVBA
4Draw S.NResultsCountDelay
5Draw S.Nn1n2n3n4n5QuadsQuadsQuads
6113/02/2004162932364116293236129
7220/02/200471339475015242844214
8327/02/20041418193137812141520
9405/03/2004473337393213034110
10512/03/200415242844474122436122
11619/03/2004333637424514152835120
12726/03/2004341023439133441113
13802/04/2004412242736515243514
14909/04/200414101923111222811
151016/04/2004141528354016293241129
161123/04/200461021454915162136117
171230/04/2004561623272027414313
181307/05/20041516213638812153410
191414/05/200413213239
201521/05/20041529373949
211628/05/20041524283244
221704/06/2004913344142
231811/06/20042781047
241918/06/2004223284043
252025/06/2004321303435
262102/07/2004812141537
272209/07/200425121944
282316/07/20042426313850
292423/07/2004710273134
302530/07/2004910193750
312606/08/2004515243544
322713/08/20042027414350
332820/08/200469102735
342927/08/2004111222844
353003/09/2004812141534
36
37
38
Join VBA Count & Delay


Macro 1 Counts...
VBA Code:
'https://www.mrexcel.com/board/threads/loop-set-of-3-within-5-results.1262915/#post-6207593
Sub Count_lottery() 'By Phuoc
Dim a As Variant, b As Variant, c As Variant
Dim i&, j&, ra&, rb&, temp$
Dim t As Double
t = Timer
a = Range("D6", Range("H" & Rows.Count).End(xlUp)).Value
b = Range("K6", Range("N" & Rows.Count).End(xlUp)).Value
ra = UBound(a, 1)
rb = UBound(b, 1)
ReDim c(1 To rb, 1 To 2)
For i = 1 To rb
    c(i, 2) = "*" & Format(b(i, 1), "00") & "|*" & Format(b(i, 2), "00") & "|*" & Format(b(i, 3), "00") & "|*" & Format(b(i, 4), "00") & "|*"
Next i
For j = 1 To ra
    temp = Format(a(j, 1), "00|") & Format(a(j, 2), "00|") & Format(a(j, 3), "00|") & Format(a(j, 4), "00|") & Format(a(j, 5), "00|")
    For i = 1 To rb
        If temp Like c(i, 2) Then c(i, 1) = c(i, 1) + 1
    Next i
Next j
Range("O6").Resize(rb, 1) = c
MsgBox Timer - t
End Sub

Macro 2 Delay...
Code:
'https://www.mrexcel.com/board/threads/find-quads-delay-loop-quads-within-5-n1-n5-results.1263090/#post-6208040
Sub Last_Delay_V2() 'By Phuoc
Dim a As Variant, b As Variant, c As Variant
Dim i&, j&, ra&, rb&, temp$
Dim t As Double
t = Timer
a = Range("D6", Range("H" & Rows.Count).End(xlUp)).Value
b = Range("K6", Range("N" & Rows.Count).End(xlUp)).Value
ra = UBound(a, 1)
rb = UBound(b, 1)
ReDim c(1 To rb, 1 To 1)

For j = 1 To ra
    a(j, 1) = Format(a(j, 1), "00|") & Format(a(j, 2), "00|") & Format(a(j, 3), "00|") & Format(a(j, 4), "00|") & Format(a(j, 5), "00|")
Next j

For i = 1 To rb
    temp = "*" & Format(b(i, 1), "00") & "|*" & Format(b(i, 2), "00") & "|*" & Format(b(i, 3), "00") & "|*" & Format(b(i, 4), "00") & "|*"
    For j = ra To 1 Step -1
        If a(j, 1) Like temp Then
           c(i, 1) = ra - j
           Exit For
        End If
    Next j
Next i
Range("P6").Resize(rb, 1) = c
MsgBox Timer - t
End Sub

Regards,
Moti
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Try this:

VBA Code:
Sub Count_And_Last_Delay() 'By Phuoc
Dim a As Variant, b As Variant, c As Variant
Dim i&, j&, ra&, rb&, temp$
Dim t As Double
t = Timer
a = Range("D6", Range("H" & Rows.Count).End(xlUp)).Value
b = Range("K6", Range("N" & Rows.Count).End(xlUp)).Value
ra = UBound(a, 1)
rb = UBound(b, 1)
ReDim c(1 To rb, 1 To 3)
For i = 1 To rb
    c(i, 3) = "*" & Format(b(i, 1), "00") & "|*" & Format(b(i, 2), "00") & "|*" & Format(b(i, 3), "00") & "|*" & Format(b(i, 4), "00") & "|*"
Next i
For j = 1 To ra
    temp = Format(a(j, 1), "00|") & Format(a(j, 2), "00|") & Format(a(j, 3), "00|") & Format(a(j, 4), "00|") & Format(a(j, 5), "00|")
    For i = 1 To rb
        If temp Like c(i, 3) Then
            c(i, 1) = c(i, 1) + 1
            c(i, 2) = ra - j
        End If
    Next i
Next j
Range("O6").Resize(rb, 2) = c
MsgBox Timer - t
End Sub
 
Upvote 1
Solution
Try this:

VBA Code:
Sub Count_And_Last_Delay() 'By Phuoc
Dim a As Variant, b As Variant, c As Variant
Dim i&, j&, ra&, rb&, temp$
Dim t As Double
t = Timer
a = Range("D6", Range("H" & Rows.Count).End(xlUp)).Value
b = Range("K6", Range("N" & Rows.Count).End(xlUp)).Value
ra = UBound(a, 1)
rb = UBound(b, 1)
ReDim c(1 To rb, 1 To 3)
For i = 1 To rb
    c(i, 3) = "*" & Format(b(i, 1), "00") & "|*" & Format(b(i, 2), "00") & "|*" & Format(b(i, 3), "00") & "|*" & Format(b(i, 4), "00") & "|*"
Next i
For j = 1 To ra
    temp = Format(a(j, 1), "00|") & Format(a(j, 2), "00|") & Format(a(j, 3), "00|") & Format(a(j, 4), "00|") & Format(a(j, 5), "00|")
    For i = 1 To rb
        If temp Like c(i, 3) Then
            c(i, 1) = c(i, 1) + 1
            c(i, 2) = ra - j
        End If
    Next i
Next j
Range("O6").Resize(rb, 2) = c
MsgBox Timer - t
End Sub
Wow Phuoc, separate each macro was taking 20 seconds total 40 second both, joining them together counts and delays both just took 20 second half of the time than individuals. 👌

I love your coding thank you for time you spent to solve my entire request.

I wish you Good Luck.

Best Regards,
Moti :)
 
Upvote 0

Forum statistics

Threads
1,221,711
Messages
6,161,450
Members
451,707
Latest member
PedroMoss2268

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top