Fill in missing sequential numbers using two value in separate columns

bchi99

Board Regular
Joined
Dec 9, 2014
Messages
56
Office Version
  1. 365
I have a random two-column sheet that I need to list the values between in a single column. The output given the following two columns below should be shown below as well. Anyone with vba knowledge help?

I NEED THIS:

42
43
44
45
46
99
100
102
55
56
57
.
.
.
90
120
121
123
.
.
.
1111
66
67
68
.
.
.
99

Current file is comprised of this original values

4246
99102
5590
1201111
6699
 
I think it would be possible to include the helper columns within the formula, but it would be really ugly.
LET makes it not-quite-so-ugly, massaged your solution a little so that it will work.
Book1
ABCDEFG
1StartEndOffsetRange sizeStartResultLET
2424605424242
39910254944343
45590936464444
54545
64646
79999
8100100
9101101
10102102
115555
125656
135757
145858
155959
166060
Sheet2
Cell Formulas
RangeFormula
C2:C4C2=SUM(C1:D1)
D2:D4D2=B2-A2+1
E2:E4E2=A2-C2
F2:F46F2=SEQUENCE(SUM(D:D),,0)+VLOOKUP(SEQUENCE(SUM(D:D),,0),C2:E4,3)
G2:G46G2=LET( begin,A2:A4, end,B2:B4, rangeSize,end-begin+1, dim,ROWS(begin), seq_r,SEQUENCE(dim), seq_c,SEQUENCE(,dim), low_triangle_matrix,IF(seq_r>seq_c,1,0), offset,MMULT(low_triangle_matrix,rangeSize), start,begin-offset, result_seq,SEQUENCE(SUM(rangeSize),,0), result_offset,INDEX(start,MATCH(result_seq,offset,1)), result,result_seq+result_offset, result )
Dynamic array formulas.
 
Upvote 0

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
A formula solution might be possible with LAMBDA, but I can't seem to figure it out.
The LET can easily be converted to a LAMBDA.
Book1
ABCDEFG
1StartEndOffsetRange sizeStartResultLAMBDA
2424605424242
39910254944343
45590936464444
5120111145992754545
66699103734-9714646
79999
8100100
9101101
10102102
115555
125656
135757
145858
155959
166060
Sheet2
Cell Formulas
RangeFormula
C2:C6C2=SUM(C1:D1)
D2:D6D2=B2-A2+1
E2:E6E2=A2-C2
F2:F1072F2=SEQUENCE(SUM(D:D),,0)+VLOOKUP(SEQUENCE(SUM(D:D),,0),C2:E6,3)
G2:G1072G2=LAMBDA(begin_rng,end_rng, LET( begin,begin_rng, end,end_rng, rangeSize,end-begin+1, dim,ROWS(begin), seq_r,SEQUENCE(dim), seq_c,SEQUENCE(,dim), low_triangle_matrix,IF(seq_r>seq_c,1,0), offset,MMULT(low_triangle_matrix,rangeSize), start,begin-offset, result_seq,SEQUENCE(SUM(rangeSize),,0), result_offset,INDEX(start,MATCH(result_seq,offset,1)), result,result_seq+result_offset, result ) )(A2:A6,B2:B6)
Dynamic array formulas.
 
Upvote 0
Assuming your values are in A2 & b2 downwards, how about
VBA Code:
Sub bchi()
   Dim Ary As Variant, Nary As Variant, s As Variant
   Dim r As Long, i As Long, nr As Long
  
   Ary = Range("A2:B" & Range("A" & Rows.Count).End(xlUp).Row).Value2
   ReDim Nary(1 To Rows.Count - 2, 1 To 1)
   For r = 1 To UBound(Ary)
      s = Evaluate("row(" & Ary(r, 1) & ":" & Ary(r, 2) & ")")
      For i = 1 To UBound(s)
         nr = nr + 1
         Nary(nr, 1) = s(i, 1)
      Next i
   Next r
   Range("E2").Resize(nr).Value = Nary
End Sub
FWIW I don't think the s array is required.

VBA Code:
Sub bchi_v2()
  Dim Ary As Variant, Nary As Variant
  Dim r As Long, i As Long, nr As Long
  
  Ary = Range("A2", Range("B" & Rows.Count).End(xlUp)).Value2
  ReDim Nary(1 To Rows.Count, 1 To 1)
  For r = 1 To UBound(Ary)
    For i = Ary(r, 1) To Ary(r, 2)
      nr = nr + 1
      Nary(nr, 1) = i
    Next i
  Next r
  Range("E2").Resize(nr).Value = Nary
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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