Need formula or VBA

Russk68

Well-known Member
Joined
May 1, 2006
Messages
589
Office Version
  1. 365
Platform
  1. MacOS
Hi
The result I need is in column LV and was manually entered. Column LZ are groups of numbers that always start from 1. The letter S also appears in this column and needs to be ignored.
Column LV starts at 1 and stops at 56. The next row starts at 1 and continues to 56 again.
I need a complete group of the same number to be within the same 56 rows. If it doesn't fit, the row number needs to restart at 1.
The white cell is the letter S just so it's not confused with the number 5.
I would prefer formulas but VB is ok!

I appreciate you!




2.14.23.1VBA.xlsm
LVLZ
411
521
631
741
851
961
1071
1181
1291
13101
14111
15121
1613S
17142
18152
19162
20172
21182
22192
23202
24212
25222
26232
2724S
28253
29263
30273
31283
32293
33303
34313
35323
36333
37343
3835S
39364
40374
41384
42394
43404
44414
45424
46434
47444
48454
49464
50474
51484
52494
5350S
5415
5525
5635
5745
5855
5965
6075
6185
6295
Bundles
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
The question is not clear, but I think this is what you want?

I've used a smaller number 12 to illustrate better. Just change the 12 to 56, and it will replicate the results you're looking for.

LVLZ
411
521
631
741
851
961
1071
1181
1291
13101
14111
15121
161S
1722
1832
1942
2052
2162
2272
2382
2492
25102
26112
2712S
2813
2923
3033
3143
3253
3363
3473
3583
3693
37103
3811S
3914
4014
4114
4224
4334
4444
4554
4664
4774
4884
4994
50104
51114
52124
531S
5425
5535
5645
5755
5865
5975
6085
6195
62105
Sheet1
Cell Formulas
RangeFormula
LV5:LV62LV5=IF(LV4+MATCH(1,--(LZ5:LZ$63<>LZ5),)-1>12,1,LV4+1)

I also wanted to show what the formula does when there are too many values, i.e. it repeats "1" until there is room to finish the 1 to 12 sequence. Is that what you want to happen? Are or you perhaps confident there won't be more than 56 repeats of the same number?

11S
14
14
14
24
34
44
54
64
74
84
94
104
114
124
1S
 
Upvote 0
The question is not clear, but I think this is what you want?

I've used a smaller number 12 to illustrate better. Just change the 12 to 56, and it will replicate the results you're looking for.

LVLZ
411
521
631
741
851
961
1071
1181
1291
13101
14111
15121
161S
1722
1832
1942
2052
2162
2272
2382
2492
25102
26112
2712S
2813
2923
3033
3143
3253
3363
3473
3583
3693
37103
3811S
3914
4014
4114
4224
4334
4444
4554
4664
4774
4884
4994
50104
51114
52124
531S
5425
5535
5645
5755
5865
5975
6085
6195
62105
Sheet1
Cell Formulas
RangeFormula
LV5:LV62LV5=IF(LV4+MATCH(1,--(LZ5:LZ$63<>LZ5),)-1>12,1,LV4+1)

I also wanted to show what the formula does when there are too many values, i.e. it repeats "1" until there is room to finish the 1 to 12 sequence. Is that what you want to happen? Are or you perhaps confident there won't be more than 56 repeats of the same number?

11S
14
14
14
24
34
44
54
64
74
84
94
104
114
124
1S
Hi Stephen
Not quite but maybe I can explain a little better.
LV and LZ are helper columns.
The purpose is to set page breaks without breaking matching sets of numbers between 2 pages.
Each page is 56 rows.
LZ is never the same size group of numbers.
LV needs to count down as close to 56 as possible without ending in the middle of a group of matching numbers.
The count in LV needs to always needs to end at a row with an S
The S represents a space between each group.
I need to get as many groups on 1 page as possible without breaking the groups.
I have code that will then reset the page breaks to a row that has an S.
 
Upvote 0
So perhaps something like this? (I've used 20, rather than 56, just to illustrate better)

LVLZ
411
521
631
741
851
961
1071
1181
1291
13101
14111
15121
1613S
1712
1822
1932
2042
2152
2262
2372
2482
2592
26102
2711S
2813
2923
3033
3143
3253
3363
3473
3583
3693
37103
3811S
3914
4024
4134
4244
4354
4464
4574
4684
4794
48104
49114
50124
51134
52144
5315S
5415
5525
5635
5745
5855
5965
6075
6185
6295
Sheet1
Cell Formulas
RangeFormula
LV5:LV62LV5=IF(LV4+IFERROR(MATCH("s",LZ5:LZ$62,),ROWS(LZ5:LZ$62))>20,1,LV4+1)
 
Upvote 0

Forum statistics

Threads
1,215,086
Messages
6,123,035
Members
449,092
Latest member
ikke

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