How To Get The Value Of The Last Non-Empty Cell In MS Excel

A photo of a woman working on a laptop

Working with large datasets in Microsoft Excel often requires you to find the last non-empty cell in a row or column. This could be useful for various reasons, such as summarizing data or ensuring your formulas are applied correctly across your dataset. In this blog post, we’ll explore several methods to achieve this in Excel.

Method 1: Using VBA (Visual Basic for Applications)

If you’re comfortable with VBA, this method can be very effective. Here’s how you can use a simple VBA code to get the value of the last non-empty cell in a column.

  1. Press ALT + F11 to open the VBA editor.
  2. Insert a new module by clicking Insert > Module.
  3. Copy and paste the following code into the module:
Function GetLastNonEmptyCellValue(col As Range) As Variant
    Dim cell As Range
    For Each cell In col
        If cell.Value <> "" Then
            GetLastNonEmptyCellValue = cell.Value
        End If
    Next cell
End Function
  1. Close the VBA editor.
  2. Use the function in Excel by typing =GetLastNonEmptyCellValue(A:A) in a cell, where A:A is the column you’re searching.

Method 2: Using the LOOKUP Function

The LOOKUP function is another effective way to find the last non-empty cell in a column.

  1. Select the cell where you want the value to appear.
  2. Enter the following formula:
=LOOKUP(2,1/(A:A<>""),A:A)

This formula works by looking for the last value in the column that is not empty. The 2 is used as a very large number to ensure the LOOKUP function finds the last entry.

Method 3: Using the INDEX and MATCH Functions

Another powerful combination in Excel is using INDEX and MATCH. Here’s how you can use these functions to find the last non-empty cell value.

  1. Select the cell where you want the value to appear.
  2. Enter the following formula:
=INDEX(A:A, MATCH(9.99999999999999E+307, A:A))

This formula works by finding the largest number that MATCH can handle, ensuring it returns the position of the last non-empty cell.

Method 4: Using the OFFSET Function

The OFFSET function can also be used to find the last non-empty cell in a column.

  1. Select the cell where you want the value to appear.
  2. Enter the following formula:
=OFFSET(A1, COUNTA(A:A)-1, 0)

s the number of non-empty cells in the column and offsets from the first cell (A1) by that number minus one.

Finding the value of the last non-empty cell in Excel can be accomplished using various methods, each suited to different comfort levels and requirements. Whether you prefer using VBA, built-in Excel functions like LOOKUP, INDEX, and MATCH, or OFFSET, you have multiple tools at your disposal to efficiently handle your data.

Experiment with these methods and find the one that best suits your needs. Happy Excel-ing!

Leave a Comment

X

Forgot Password?

Join Us

Scroll to Top