VBA 10th Line of data to Another Sheet

Stephen_IV

Well-known Member
Joined
Mar 17, 2003
Messages
1,177
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Good afternoon,

I have a sample data set below.I have over 500,000 records. Each child can have from 1 to 182 days absent (1 to 182 lines of data). What I need to do is to have VBA list on Sheet2 every 10th school or 10th line per Id number and if the child does not have 10 absences then bring back 0. Thanks in advance!

For the sample below:
11111 10th line is 102
22222 10th line is 114

Thanks in advance
<style type="text/css">
table.tableizer-table {
font-size: 8px;
border: 1px solid #CCC ;
font-family: Arial, Helvetica, sans-serif;
}
.tableizer-table td {
padding: 4px;
margin: 3px;
border: 1px solid #CCC ;
}
.tableizer-table th {
background-color: #104E8B ;
color: #FFF ;
font-weight: bold;
}
</style>
<table class="tableizer-table">
<thead><tr class="tableizer-firstrow"><th>ID</th><th>School</th><th>Date</th><th>DESCRIPTION</th></tr></thead><tbody>
<tr><td>11111</td><td>100</td><td>9/1/2016</td><td>Absent</td></tr>
<tr><td>11111</td><td>100</td><td>9/2/2016</td><td>Unexcused Absence</td></tr>
<tr><td>11111</td><td>100</td><td>9/5/2016</td><td>Absent</td></tr>
<tr><td>11111</td><td>100</td><td>9/6/2016</td><td>Absent</td></tr>
<tr><td>11111</td><td>100</td><td>9/7/2016</td><td>Absent</td></tr>
<tr><td>11111</td><td>100</td><td>9/8/2016</td><td>Absent</td></tr>
<tr><td>11111</td><td>100</td><td>9/9/2016</td><td>Absent</td></tr>
<tr><td>11111</td><td>100</td><td>9/12/2016</td><td>Absent</td></tr>
<tr><td>11111</td><td>100</td><td>9/13/2016</td><td>Absent</td></tr>
<tr><td>11111</td><td>102</td><td>9/14/2016</td><td>Absent</td></tr>
<tr><td>11111</td><td>102</td><td>9/15/2016</td><td>Absent</td></tr>
<tr><td>11111</td><td>103</td><td>9/16/2016</td><td>Absent</td></tr>
<tr><td>11111</td><td>103</td><td>9/19/2016</td><td>Absent</td></tr>
<tr><td>22222</td><td>102</td><td>9/20/2016</td><td>Absent</td></tr>
<tr><td>22222</td><td>102</td><td>9/21/2016</td><td>Unexcused Absence</td></tr>
<tr><td>22222</td><td>102</td><td>9/22/2016</td><td>Absent</td></tr>
<tr><td>22222</td><td>102</td><td>9/23/2016</td><td>Absent</td></tr>
<tr><td>22222</td><td>102</td><td>9/26/2016</td><td>Unexcused Absence</td></tr>
<tr><td>22222</td><td>102</td><td>9/27/2016</td><td>Absent</td></tr>
<tr><td>22222</td><td>102</td><td>9/28/2016</td><td>Absent</td></tr>
<tr><td>22222</td><td>102</td><td>9/29/2016</td><td>Absent</td></tr>
<tr><td>22222</td><td>102</td><td>9/30/2016</td><td>Unexcused Absence</td></tr>
<tr><td>22222</td><td>114</td><td>10/3/2016</td><td>Absent</td></tr>
<tr><td>22222</td><td>114</td><td>10/4/2016</td><td>Absent</td></tr>
<tr><td>22222</td><td>116</td><td>10/5/2016</td><td>Unexcused Absence</td></tr>
</tbody></table>
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
If you are amenable to an alternative, you could add a column that counts absences:

[Table="width:, class:grid"][tr][td="bgcolor:#C0C0C0"][/td][td="bgcolor:#C0C0C0"]
A​
[/td][td="bgcolor:#C0C0C0"]
B​
[/td][td="bgcolor:#C0C0C0"]
C​
[/td][td="bgcolor:#C0C0C0"]
D​
[/td][td="bgcolor:#C0C0C0"]
E​
[/td][td="bgcolor:#C0C0C0"]
F​
[/td][/tr][tr][td="bgcolor:#C0C0C0"]
1​
[/td][td="bgcolor:#F3F3F3"]
ID
[/td][td="bgcolor:#F3F3F3"]
School
[/td][td="bgcolor:#F3F3F3"]
Date
[/td][td="bgcolor:#F3F3F3"]
DESCRIPTION
[/td][td="bgcolor:#F3F3F3"]
Count
[/td][td="bgcolor:#F3F3F3"]
[/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
2​
[/td][td]
11111​
[/td][td]
100​
[/td][td]
9/1/2016​
[/td][td]Absent[/td][td="bgcolor:#E5E5E5"]
1​
[/td][td]E2: =COUNTIF(INDEX(A:A, MAX(2, ROW() - 182)):A2, A2)[/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
3​
[/td][td]
11111​
[/td][td]
100​
[/td][td]
9/2/2016​
[/td][td]Unexcused Absence[/td][td="bgcolor:#E5E5E5"]
2​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
4​
[/td][td]
11111​
[/td][td]
100​
[/td][td]
9/5/2016​
[/td][td]Absent[/td][td="bgcolor:#E5E5E5"]
3​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
5​
[/td][td]
11111​
[/td][td]
100​
[/td][td]
9/6/2016​
[/td][td]Absent[/td][td="bgcolor:#E5E5E5"]
4​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
6​
[/td][td]
11111​
[/td][td]
100​
[/td][td]
9/7/2016​
[/td][td]Absent[/td][td="bgcolor:#E5E5E5"]
5​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
7​
[/td][td]
11111​
[/td][td]
100​
[/td][td]
9/8/2016​
[/td][td]Absent[/td][td="bgcolor:#E5E5E5"]
6​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
8​
[/td][td]
11111​
[/td][td]
100​
[/td][td]
9/9/2016​
[/td][td]Absent[/td][td="bgcolor:#E5E5E5"]
7​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
9​
[/td][td]
11111​
[/td][td]
100​
[/td][td]
9/12/2016​
[/td][td]Absent[/td][td="bgcolor:#E5E5E5"]
8​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
10​
[/td][td]
11111​
[/td][td]
100​
[/td][td]
9/13/2016​
[/td][td]Absent[/td][td="bgcolor:#E5E5E5"]
9​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
11​
[/td][td]
11111​
[/td][td]
102​
[/td][td]
9/14/2016​
[/td][td]Absent[/td][td="bgcolor:#E5E5E5"]
10​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
12​
[/td][td]
11111​
[/td][td]
102​
[/td][td]
9/15/2016​
[/td][td]Absent[/td][td="bgcolor:#E5E5E5"]
11​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
13​
[/td][td]
11111​
[/td][td]
103​
[/td][td]
9/16/2016​
[/td][td]Absent[/td][td="bgcolor:#E5E5E5"]
12​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
14​
[/td][td]
11111​
[/td][td]
103​
[/td][td]
9/19/2016​
[/td][td]Absent[/td][td="bgcolor:#E5E5E5"]
13​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
15​
[/td][td]
22222​
[/td][td]
102​
[/td][td]
9/20/2016​
[/td][td]Absent[/td][td="bgcolor:#E5E5E5"]
1​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
16​
[/td][td]
22222​
[/td][td]
102​
[/td][td]
9/21/2016​
[/td][td]Unexcused Absence[/td][td="bgcolor:#E5E5E5"]
2​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
17​
[/td][td]
22222​
[/td][td]
102​
[/td][td]
9/22/2016​
[/td][td]Absent[/td][td="bgcolor:#E5E5E5"]
3​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
18​
[/td][td]
22222​
[/td][td]
102​
[/td][td]
9/23/2016​
[/td][td]Absent[/td][td="bgcolor:#E5E5E5"]
4​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
19​
[/td][td]
22222​
[/td][td]
102​
[/td][td]
9/26/2016​
[/td][td]Unexcused Absence[/td][td="bgcolor:#E5E5E5"]
5​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
20​
[/td][td]
22222​
[/td][td]
102​
[/td][td]
9/27/2016​
[/td][td]Absent[/td][td="bgcolor:#E5E5E5"]
6​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
21​
[/td][td]
22222​
[/td][td]
102​
[/td][td]
9/28/2016​
[/td][td]Absent[/td][td="bgcolor:#E5E5E5"]
7​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
22​
[/td][td]
22222​
[/td][td]
102​
[/td][td]
9/29/2016​
[/td][td]Absent[/td][td="bgcolor:#E5E5E5"]
8​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
23​
[/td][td]
22222​
[/td][td]
102​
[/td][td]
9/30/2016​
[/td][td]Unexcused Absence[/td][td="bgcolor:#E5E5E5"]
9​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
24​
[/td][td]
22222​
[/td][td]
114​
[/td][td]
10/3/2016​
[/td][td]Absent[/td][td="bgcolor:#E5E5E5"]
10​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
25​
[/td][td]
22222​
[/td][td]
114​
[/td][td]
10/4/2016​
[/td][td]Absent[/td][td="bgcolor:#E5E5E5"]
11​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
26​
[/td][td]
22222​
[/td][td]
116​
[/td][td]
10/5/2016​
[/td][td]Unexcused Absence[/td][td="bgcolor:#E5E5E5"]
12​
[/td][td][/td][/tr]
[/table]


The formula is a little exotic sou it doesn't have to look at 500,000 rows, and it requires that the table be sorted by ID (as it is now). Then you can filter on that column for >= 10:

[Table="width:, class:grid"][tr][td="bgcolor:#C0C0C0"][/td][td="bgcolor:#C0C0C0"]
A​
[/td][td="bgcolor:#C0C0C0"]
B​
[/td][td="bgcolor:#C0C0C0"]
C​
[/td][td="bgcolor:#C0C0C0"]
D​
[/td][td="bgcolor:#C0C0C0"]
E​
[/td][/tr][tr][td="bgcolor:#C0C0C0"]
1​
[/td][td="bgcolor:#F3F3F3"]
ID
[/td][td="bgcolor:#F3F3F3"]
School
[/td][td="bgcolor:#F3F3F3"]
Date
[/td][td="bgcolor:#F3F3F3"]
DESCRIPTION
[/td][td="bgcolor:#F3F3F3"]
Count
[/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
11​
[/td][td]
11111​
[/td][td]
102​
[/td][td]
9/14/2016​
[/td][td]Absent[/td][td="bgcolor:#E5E5E5"]
10​
[/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
12​
[/td][td]
11111​
[/td][td]
102​
[/td][td]
9/15/2016​
[/td][td]Absent[/td][td="bgcolor:#E5E5E5"]
11​
[/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
13​
[/td][td]
11111​
[/td][td]
103​
[/td][td]
9/16/2016​
[/td][td]Absent[/td][td="bgcolor:#E5E5E5"]
12​
[/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
14​
[/td][td]
11111​
[/td][td]
103​
[/td][td]
9/19/2016​
[/td][td]Absent[/td][td="bgcolor:#E5E5E5"]
13​
[/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
24​
[/td][td]
22222​
[/td][td]
114​
[/td][td]
10/3/2016​
[/td][td]Absent[/td][td="bgcolor:#E5E5E5"]
10​
[/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
25​
[/td][td]
22222​
[/td][td]
114​
[/td][td]
10/4/2016​
[/td][td]Absent[/td][td="bgcolor:#E5E5E5"]
11​
[/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
26​
[/td][td]
22222​
[/td][td]
116​
[/td][td]
10/5/2016​
[/td][td]Unexcused Absence[/td][td="bgcolor:#E5E5E5"]
12​
[/td][/tr]
[/table]
 
Upvote 0
shg,

Love the formula! I can make it work. I'm surprised how fast it is! Thank you again for your help and guidance!
 
Upvote 0
I'm pleased it will work for you, you're welcome.
 
Upvote 0
Doh, that was a needlessly complicated formula. Assuming there are no blank rows, and the data is sorted by ID, then

[Table="width:, class:grid"][tr][td="bgcolor:#C0C0C0"][/td][td="bgcolor:#C0C0C0"]
A​
[/td][td="bgcolor:#C0C0C0"]
B​
[/td][td="bgcolor:#C0C0C0"]
C​
[/td][td="bgcolor:#C0C0C0"]
D​
[/td][td="bgcolor:#C0C0C0"]
E​
[/td][td="bgcolor:#C0C0C0"]
F​
[/td][/tr][tr][td="bgcolor:#C0C0C0"]
1​
[/td][td="bgcolor:#F3F3F3"]
ID
[/td][td="bgcolor:#F3F3F3"]
School
[/td][td="bgcolor:#F3F3F3"]
Date
[/td][td="bgcolor:#F3F3F3"]
DESCRIPTION
[/td][td="bgcolor:#F3F3F3"]
Count
[/td][td="bgcolor:#F3F3F3"]
[/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
2​
[/td][td]
11111​
[/td][td]
100​
[/td][td]
9/1/2016​
[/td][td]Absent[/td][td="bgcolor:#E5E5E5"]
1​
[/td][td]E2: =IF(A2=A1, E1+1, 1)[/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
3​
[/td][td]
11111​
[/td][td]
100​
[/td][td]
9/2/2016​
[/td][td]Unexcused Absence[/td][td="bgcolor:#E5E5E5"]
2​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
4​
[/td][td]
11111​
[/td][td]
100​
[/td][td]
9/5/2016​
[/td][td]Absent[/td][td="bgcolor:#E5E5E5"]
3​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
5​
[/td][td]
11111​
[/td][td]
100​
[/td][td]
9/6/2016​
[/td][td]Absent[/td][td="bgcolor:#E5E5E5"]
4​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
6​
[/td][td]
11111​
[/td][td]
100​
[/td][td]
9/7/2016​
[/td][td]Absent[/td][td="bgcolor:#E5E5E5"]
5​
[/td][td][/td][/tr]
[/table]


... is all you need.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,711
Messages
6,174,020
Members
452,542
Latest member
Bricklin

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