Count Skips Between Last Occurrence

Poker Joe

New Member
Joined
Feb 12, 2015
Messages
30
Office Version
  1. 2019
Platform
  1. Windows
Sheet 1

IDDateN1N2N3N4N5

8472/27/20211016172436
8482/28/202169131422
8493/1/202126182333
8503/2/2021915202734
8513/3/20211922232435
8523/4/2021613203336
8533/5/2021314152036
8543/6/2021112152043
8553/7/20211115161843
8563/8/20211630313940
8573/9/2021320253043
8583/10/20211820252829
8593/11/2021210132930
8603/12/2021518193839
8613/13/2021511202126
8623/14/2021712252841
8633/15/20211337383943
8643/16/2021310112241
8653/17/20211516171937
8663/18/20211824283139
8673/19/2021513222734
8683/20/20211516212437
8693/21/20211314182429
8703/22/2021918323334
8713/23/2021112183236
8723/24/202168132936
8733/25/2021912162035
8743/26/2021628333639
8753/27/202167222332
8763/28/202126111331



Sheet 2

#SBLO
15
20
312
447
59
60
71
84
93
1012
110
123
130
147
158
163
1711
185
1911
203
218
221
231
246
2514
2615
279
282
294
3017
310
321
332
346
353
362
378
3813
392
4020
4112
4237
4313


Sheet1 contains a list of drawings. The numbers are in Columns C through G. One row for each drawing.
Sheet2 contains numbers 1-43 of which 5 will be selected for the next drawing.

In Sheet2 Column B (SBLO) is where I want to place the number of drawings Skipped Between the Last Occurance for each number in Column A (#).

The Sheet2 example has the results I'm seeking in Column B (SBLO) according to the latest drawings in Sheet1.
[IMPORTANT] I didn't template the full history of drawings in my Sheet1 example. The #4 on Sheet2 shows 47 skips between last occurance but to save space I didn't list the drawings that far back.

Ex. 2-6-11-13-31 was the last drawing on Sheet1 so they will have 0 skips between last occurance on Sheet2. The drawing before that on Sheet1 was 6-7-22-23-32. Numbers# 7, 22, 23, 32 on Sheet2 will have 1 skip between last occurance, 6 already has 0, etc. etc.

Hey, I know it's a lottery Sub I'm seeking but it's a fun way to learn Excel VBA.

I'm wondering whether I need to define two ranges, one in Sheet1 and one in Sheet2.

Lame attempt below. This is stuff I mashed together from my little subroutine library but it definitely has big holes in it. I'm far from being VBA proficient. I only know enough to be dangerous and always frustrated.

Thanks in advance to anyone willing to help.


VBA Code:
Sub Count_SBLO()
'
' 
'

'
Dim myRange As Range
Dim c As Range
Set drwgRange = Sheet1.Range("C3", Range("G1048576").End(xlUp))
   
    For Each c In myRange
        For i = c.Row - 2 To 1 Step -1
            If Not IsError(Application.Match(c, drwgRange.Rows(i), 0)) Then
                c.Offset(, 1) = c.Row - 1 - i
                Exit For
            Else
                c.Offset(, 1) = 0
            End If
        Next i
    Next c
End Sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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