# Counting Two Number Sequences

#### Necroscope

##### Board Regular
Hello all. I hope you can help with this. It sounds simple in my head but I can't figure out the formula!

A1 and B1 have the numbers 100 and 199 in them. (It's a range of 100 ticket numbers.)
A2 and B2 have the numbers 500 and 599. (Another range of 100.)

In C1, I have typed in 120. What I want Excel to do is say that in order to meet the figure of 120, all tickets from the first batch need to be used and 20 tickets from the second batch need to be used. Ie ticket numbers 100 to 199 and 500 to 519 are used up.

The second part of the problem is that I'd also like to enter another number - for example 50 - and Excel would know to look at the available tickets from the second batch because the first batch is gone. I.e ticket numbers 520 to 569.

Is there a non-VBA way to do this?

TIA

### 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.

#### Peter_SSs

##### MrExcel MVP, Moderator
Necroscope

I am sure there is. If I have understood correctly, then here is one way. I have ussed quite a few 'helper' columns so that the formulas don't become too long. Provided the formulas have been entered far enough down in these extra columns, the columns could be hidden if desired.

C3: =F3-D3
D3: =MIN(MAX(0,G3-\$I\$3),F3)
F3: =IF(COUNT(A3:B3)=2,B3-A3+1,"")
G3: =IF(F3="","",G2+F3)
I3: =SUM(H:H)

All formulas (except I3) copied down. The numbers you referred to as being entered in column C, I have entered in column H. However, all columns can be re-arranged as you see fit.

Mr Excel.xls
ABCDEFGHI
1Used from this batchRemaining from this batchTickets in BatchTotal TicketsUsedTotal Used
2
3100199100010010080140
4500599406010020010
5800899010010030030
611001199010010040020
7
8
Tickets

#### BrianB

##### Well-known Member
This might be what you want. Keeps a running total of the balance at each entry, so you can add batches of tickets/requirements below as required.

A2 has your start batch number
B2 has your end batch number
C2 has formula =B2-A2+1
D2 has your number eg. 120 required
E2 has formula =SUM(\$C\$2:C100)-SUM(\$D\$1:D2)
(watch the \$ positions - can copy/paste the formula from here)
can copy formulas down.

#### Necroscope

##### Board Regular
Peter and Brian. Thanks to you both for your help. Both work great so I'll tinker around with what I ultimately want to produce and use your formula.

Richard

Replies
5
Views
272
Replies
0
Views
196
Replies
3
Views
103
Replies
1
Views
301
Replies
4
Views
201