# Which non-contiguous range contains value?

#### LloydFinancials

##### Well-known Member
A B
1 (14.73) (16.29)
2 500.00 600.00
3 1,045.92 1,156.02

A is one end of range, B is the other. Formula to determine which range contains the value 501.00 and return the row number. The next list may have 9 rows or more, so cannot enter if statements to check every single row. Formula preferred.

### Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Try:

#### LloydFinancials

##### Well-known Member
Thank you. Appreciate the effort. When I put in -15.00, I get a #NUM ! error instead of 1.

#### Eric W

##### MrExcel MVP
That's because -14.73 is greater than -16.29. The formula works if the lower values are in A, higher values in B. If you don't know what order they'll be in, the formula gets tougher. Like:

=AGGREGATE(15,6,ROW(A1:A3)/((SUBTOTAL(5,OFFSET(A1:B1,ROW(A1:A3)-ROW(A1),0))<=E2)*(E2<=SUBTOTAL(4,OFFSET(A1:B1,ROW(A1:A3)-ROW(A1),0)))),1)

#### LloydFinancials

##### Well-known Member
makes sense, thank you, I can reverse the order

#### DanteAmor

##### Well-known Member
Other option:

If you order the data from least to greatest

=SUMPRODUCT((A1:A3<=E2)*(B1:B3>=E2)*ROW(A1:A3))

If not:

=SUMPRODUCT(((A1:A3<=E2)*(B1:B3>=E2)+(A1:A3>=E2)*(B1:B3<=E2))*FILA(A1:A3))

Last edited:

#### Peter_SSs

##### MrExcel MVP, Moderator
If not:

=SUMPRODUCT(((A1:A3<=E2)*(B1:B3>=E2)+(A1:A3>=E2)*(B1:B3<=E2))*FILA(A1:A3))

Hi Dante,

I assume that you are normally translating your formulas from Spanish to English & you missed FILA in that one.
so I assume should be

=SUMPRODUCT(((A1:A3<=E2)*(B1:B3>=E2)+(A1:A3>=E2)*(B1:B3<=E2))*ROW(A1:A3))

@LloydFinancials
With your pairs unsorted and any way around, I think this more concise one should also work for you. It does assume that the value being checked resides in at most one of the column A:B pairs.
If the value does not reside in any of the pairs the formula returns zero, as shown in row 4.

Excel Workbook
ABCDEF
1-14.73-16.29ValueRow
25006005012
31045.921156.02-151
47000
51156.023
65002
Row

Last edited:

#### Peter_SSs

##### MrExcel MVP, Moderator
If you are only interested in row relative to your table then you could try the column F formula below. It is an array formula so should be entered without the {} but confirmed with Ctrl+Shift+Enter, not just Enter. If confirmed correctly, Excel will insert the {}. The formula can then be copied down.

If you prefer to avoid the array-entry then you could try the standard-entry version shown in column G.

In these instances you will see an error, rather than 0, is generated if the value does not occur in any pair.

Excel Workbook
ABCDEFG
3
4-14.73-16.29ValueRow
550060050122
61045.921156.02-1511
7700#N/A#N/A
81156.0233
950022
10
Row

#### DanteAmor

##### Well-known Member
Hi Dante,

I assume that you are normally translating your formulas from Spanish to English & you missed FILA in that one.
so I assume should be

=SUMPRODUCT(((A1:A3<=E2)*(B1:B3>=E2)+(A1:A3>=E2)*(B1:B3<=E2))*ROW(A1:A3))
I'm sorry about that. Appreciation is correct. thanks Peter.

Last edited by a moderator:

#### Peter_SSs

##### MrExcel MVP, Moderator
I'm sorry about that. Appreciation is correct. thanks Peter.
No problem. It must be a bit annoying having to translate all the time.
Do you normally do it manually or use a translator like this?

BTW, I trimmed your quote of my post since you were really only referring to the part about the formula translation, not my other suggestion to the OP.

1,102,726
Messages
5,488,521
Members
407,643
Latest member
samerf86

### This Week's Hot Topics

• Timer in VBA - Stop, Start, Pause and Reset
[CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
• how to updates multiple rows in muliselect listbox
Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
• Delete Row from Table
I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
• Assigning to a variable
I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
• Way to verify information
Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
• Active Cell Address – Inactive Sheet
How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...