How to Retrieve the Rightmost Numeric Value in an Excel Range Using INDEX, MATCH, and LOOKUP Functions

スポンサーリンク
スポンサーリンク

How to Return the Rightmost Number from a Range?

In Excel, you may need to retrieve the rightmost numeric value from a row containing numbers, text, and blank cells. For example, when tracking monthly sales or periodically updated data, you might want to return the latest numerical entry without manually checking each cell.

This article explains two methods for finding the rightmost numeric value in a horizontal range, regardless of whether the numbers are sorted. Both methods ignore text and blank cells.

Method 1: Using the INDEX and XMATCH Functions

The combination of the INDEX and XMATCH functions provides a reliable way to retrieve the rightmost numeric value in a range.

Unlike the traditional MATCH function, XMATCH supports searching from right to left. By combining it with ISNUMBER, you can locate the last numeric value even when the range contains text, blanks, or unsorted numbers.

How to Use INDEX and XMATCH

The ISNUMBER function checks whether each cell contains a numeric value. The XMATCH function searches from the rightmost cell to the left and identifies the first numeric match. Finally, the INDEX function returns the corresponding value.

The basic syntax of INDEX is:

=INDEX(range, row_number, column_number)

To find the position of the rightmost numeric value, use:

=XMATCH(TRUE, ISNUMBER(A1:D1), 0, -1)

Here:

  • ISNUMBER(A1:D1) checks which cells contain numbers and returns TRUE or FALSE for each cell.
  • TRUE specifies that XMATCH should find a numeric cell.
  • 0 specifies an exact match.
  • -1 specifies searching from the last cell to the first.

To return the corresponding value, combine INDEX and XMATCH:

=INDEX(A1:D1, 1, XMATCH(TRUE, ISNUMBER(A1:D1), 0, -1))

Example: Retrieve the Rightmost Numeric Value

Consider the following table:

A B C D
1 10 40 Text 20

To retrieve the rightmost numeric value from A1:D1, enter:

=INDEX(A1:D1, 1, XMATCH(TRUE, ISNUMBER(A1:D1), 0, -1))

The result is:

20

Although 40 is the largest number in the range, 20 is the rightmost numeric value. The formula correctly returns 20 without requiring the data to be sorted.

Notes:

  • XMATCH is available in Microsoft 365, Excel 2021, Excel 2024, and supported newer versions.
  • The search mode -1 allows XMATCH to search from right to left without sorting the data.
  • The ISNUMBER function ignores text values, blank cells, and errors when identifying numeric cells.
  • Negative numbers and zero are recognized as numeric values.
  • Numbers stored as text, such as "100", are not recognized as numeric values by ISNUMBER.
  • INDEX uses positions relative to the specified range. For example, if the range is B2:D2, B2 is position (1,1).
  • If no numeric value exists in the range, XMATCH returns a #N/A error.

Handling Ranges Without Numeric Values

If the range may contain no numeric values, use IFERROR to display a message instead of an error:

=IFERROR(INDEX(A1:D1, 1, XMATCH(TRUE, ISNUMBER(A1:D1), 0, -1)), "No numeric value")

If no numeric value is found, the formula displays:

No numeric value

Method 2: Using the LOOKUP Function

The LOOKUP function provides an alternative method for retrieving the rightmost numeric value. This method is particularly useful when working with older versions of Excel that do not support XMATCH.

Although the ordinary LOOKUP function generally requires sorted lookup data, it can be combined with ISNUMBER to create a lookup array containing only 1 and error values. This technique makes it possible to identify the rightmost numeric entry without sorting the original data.

How to Use the LOOKUP Function

The basic syntax of the LOOKUP function in vector form is:

=LOOKUP(lookup_value, lookup_vector, [result_vector])

To retrieve the rightmost numeric value in A1:D1, use:

=LOOKUP(2, 1/ISNUMBER(A1:D1), A1:D1)

This formula works as follows:

  • ISNUMBER(A1:D1) checks each cell and returns TRUE for numbers and FALSE for other values.
  • 1/ISNUMBER(A1:D1) converts TRUE values into 1 and FALSE values into #DIV/0! errors.
  • LOOKUP(2,...) searches for 2. Because the numeric entries in the lookup array are all 1, LOOKUP finds the last matching 1 while ignoring the error values.
  • A1:D1 specifies the range from which the corresponding numeric value is returned.

This technique does not depend on the order of the original numeric values.

Example: Using LOOKUP to Retrieve the Rightmost Numeric Value

Using the same example:

A B C D
1 10 40 Text 20

Enter the following formula:

=LOOKUP(2, 1/ISNUMBER(A1:D1), A1:D1)

The result is:

20

The formula ignores the text in C1 and returns the value from D1, which is the rightmost numeric cell.

Example: Ignore Blank Cells and Text

Suppose a range contains the following values:

A B C D E
1 100 50 Pending

Enter:

=LOOKUP(2, 1/ISNUMBER(A1:E1), A1:E1)

The result is:

50

The formula ignores blank cells and text, returning the numeric value in C1.

Handling Ranges Without Numeric Values

If the range contains no numeric values, the LOOKUP formula returns an error because no matching numeric position can be found.

To display an empty cell instead, use:

=IFERROR(LOOKUP(2, 1/ISNUMBER(A1:D1), A1:D1), "")

This returns an empty string when no numeric value is found.

Notes:

  • This method works with many older Excel versions, including versions without XMATCH.
  • It does not require the original numeric data to be sorted.
  • The formula recognizes positive numbers, negative numbers, and zero.
  • Text and blank cells are excluded from the search.
  • Numeric-looking text is not treated as a number.
  • Excel dates are stored as serial numbers, so valid date values may also be recognized as numeric values.
  • The formula is intended for a single horizontal row. For a vertical range, the same technique can retrieve the bottommost numeric value.

Important Considerations

When retrieving the rightmost numeric value, it is important to distinguish between finding the largest number and finding the last number by position.

  • Rightmost value versus maximum value: The rightmost numeric value is the number located farthest to the right, regardless of its magnitude. The MAX function returns the largest numeric value instead.
  • Unsorted data: Formulas such as MATCH(1E+30, A1:D1) or LOOKUP(1E+30, A1:D1) are not reliable for unsorted data because their approximate matching behavior normally depends on ascending order.
  • Blank cells: Both methods described in this article ignore blank cells.
  • Text values: Both methods exclude text, including numbers stored as text.
  • Zero and negative values: Both methods correctly recognize zero and negative numbers.
  • Formula results: A cell containing a formula that returns a number is recognized as numeric. A formula returning text, including an empty string, is excluded.
  • Error handling: Use IFERROR when the range may not contain any numeric values.
  • Horizontal ranges: The examples in this article use a single row. INDEX with XMATCH can also be adapted to other range layouts.

Summary

To retrieve the rightmost numeric value from a horizontal range in Excel, the INDEX and XMATCH combination is a reliable choice for modern Excel versions. It explicitly searches from right to left and does not require the values to be sorted.

For older Excel versions, the LOOKUP and ISNUMBER combination offers a practical alternative that works even when numbers, text, and blank cells are mixed.

The recommended formulas are:

  • Modern Excel (INDEX and XMATCH):
    =INDEX(A1:D1, 1, XMATCH(TRUE, ISNUMBER(A1:D1), 0, -1))
  • Older Excel (LOOKUP and ISNUMBER):
    =LOOKUP(2, 1/ISNUMBER(A1:D1), A1:D1)

Both methods return the rightmost numeric value rather than the maximum value, making them useful for retrieving the latest numerical entries in reports, tracking sheets, and other Excel datasets.