Find quads delay (Loop quads within 5 n1:n5 results)

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,422
Office Version
  1. 2010
Using Excel 2010

Hello, I got lottery results in column D:H approximately 2000+ rows, and set of quads in column K:N approximately 65000+ rows, I need a VBA which can loop quads… through column D:H and generate the find DELAY result in column O as shown in the few lines example below.

Find Dealy MrExcel.xlsm
ABCDEFGHIJKLMNOPQR
1
2Example Results
330Need VBA To Find
4Last Delay
5DrawDaten1n2n3n4n5QuadsLoop Delay Within n1:n5
6113/02/200416293236411629323629<--Last Appeared In Draw 1 (Total Draw=30) So Delay = 29
7220/02/20047133947501524284414<--Last Appeared In Draw 16 (Total Draw=30) So Delay = 14
8327/02/2004141819313781214159<--Last Appeared In Draw 21 (Total Draw=30) So Delay = 9
9405/03/200447333739321303410<--Last Appeared In Draw 20 (Total Draw=30) So Delay = 10
10512/03/20041524284447412243622<--Last Appeared In Draw 8 (Total Draw=30) So Delay = 22
11619/03/2004333637424514152835?
12726/03/2004341023439133441?
13802/04/20044122427365152435?
14909/04/2004141019231112228?
151016/04/2004141528354016293241?
161123/04/200461021454915162136?
171230/04/20045616232720274143?
181307/05/2004151621363881215340<--Last Appeared In Draw 30 (Total Draw=30) So Delay = 0
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
Find Last Delay
Cell Formulas
RangeFormula
C3C3=MAX(IF(C6:C35<>"",ROW(C6:C35)))-5
Press CTRL+SHIFT+ENTER to enter array formulas.


Regards,
Moti
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Not VBA, nor the cleanest method, but it gets the job done for excel 2010:

Book1
BCDEFGHIJKLMNOP
1
2Example Results
330Need VBA To Find
4Last Delay
5DrawDaten1n2n3n4n5QuadsLoop Delay Within n1:n5
6113/02/200416293236411629323629<--Last Appeared In Draw 1 (Total Draw=30) So Delay = 29
7220/02/20047133947501524284414<--Last Appeared In Draw 16 (Total Draw=30) So Delay = 14
8327/02/2004141819313781214159<--Last Appeared In Draw 21 (Total Draw=30) So Delay = 9
9405/03/200447333739321303410<--Last Appeared In Draw 20 (Total Draw=30) So Delay = 10
10512/03/20041524284447412243622<--Last Appeared In Draw 8 (Total Draw=30) So Delay = 22
11619/03/200433363742451415283520
12726/03/200434102343913344113
13802/04/200441224273651524354
14909/04/20041410192311122281
151016/04/200414152835401629324129
161123/04/20046102145491516213617
171230/04/200456162327202741433
181307/05/2004151621363881215340<--Last Appeared In Draw 30 (Total Draw=30) So Delay = 0
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
Sheet8
Cell Formulas
RangeFormula
C3C3=MAX(IF(C6:C3000<>"",ROW(C6:C3000)))-5
O6:O18O6=$C$3-MAX( IFERROR(MATCH(($K6&"|"&$L6&"|"&$M6&"|"&$N6), ( $D$6:$D$3000&"|"&$E$6:$E$3000&"|"&$F$6:$F$3000&"|"&$G$6:$G$3000), 0), 0), IFERROR(MATCH(($K6&"|"&$L6&"|"&$M6&"|"&$N6), ( $D$6:$D$3000&"|"&$E$6:$E$3000&"|"&$F$6:$F$3000&"|"&$H$6:$H$3000), 0), 0), IFERROR(MATCH(($K6&"|"&$L6&"|"&$M6&"|"&$N6), ( $D$6:$D$3000&"|"&$E$6:$E$3000&"|"&$G$6:$G$3000&"|"&$H$6:$H$3000), 0), 0), IFERROR(MATCH(($K6&"|"&$L6&"|"&$M6&"|"&$N6), ( $D$6:$D$3000&"|"&$F$6:$F$3000&"|"&$G$6:$G$3000&"|"&$H$6:$H$3000), 0), 0), IFERROR(MATCH(($K6&"|"&$L6&"|"&$M6&"|"&$N6), ( $E$6:$E$3000&"|"&$F$6:$F$3000&"|"&$G$6:$G$3000&"|"&$H$6:$H$3000), 0), 0) )
 
Upvote 1
Not VBA, nor the cleanest method, but it gets the job done for excel 2010:
Hello felixstraube, this is amazing, I tried with my original data as per post#1 results in column D:H approximately 2000+ rows, and set of quads in column K:N approximately 65000+ rows, speechless by your excel art work, formula worked like magic 100% perfect. :love: I am using it now, may someone make it shorter or provide VBA solution.

I am happy by your help and appreciate it. Have a pleasant time. Good Luck.

Best Regards,
Moti :)
 
Upvote 0
Try this code:
VBA Code:
Sub Last_Delay()
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 = ra To 1 Step -1
    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 c(i, 1) = "" Then
            If temp Like c(i, 2) Then c(i, 1) = ra - j
        End If
    Next i
Next j
Range("P6").Resize(rb, 1) = c
MsgBox Timer - t
End Sub
 
Upvote 1
Try this code:
Hello Phuoc, this is remarkable, I tried with my original data as per post#1 results in column D:H approximately 2000+ rows, and set of quads in column K:N approximately 65000+ rows, speechless by your excel art work, VBA worked like magic with 100% accuracy. It took only 28 second to accomplish find the delays. You made my day (y) :love:

I am happy and admire your kind help. Have a great weekend. Good Luck.

Best Regards,
Moti :)
 
Upvote 0
If K:N is 65000+ rows and D:H is 2000+ rows, try this code:

VBA Code:
Sub Last_Delay_V2()
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
 
Upvote 1
Solution
If K:N is 65000+ rows and D:H is 2000+ rows, try this code:
Hello Phuoc, this macro took only and only 20 second to finish to find last delays and with 100% accuracy too. This is really time saver version. 🥰 I am grateful with your kind help. 🙏

Have a peaceful and joyful weekend. Good Luck.

Best Regards,
Moti :)
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,623
Latest member
Techenthusiast

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