Find the Last Nonzero Row in Excel Column Q with VBA
Question details
Find the last row in column Q that contains a nonzero value using VBA or an evaluated Excel formula.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A user needs the row number of the last nonzero value within a specified range in column Q.
- Observed behavior
- The desired result is the greatest row number containing a nonzero value, or an indication that no matching value exists.
Check the range you want to search in column Q. The example uses Q2:Q1000 and assumes the cells contain numbers or are blank, with no error values or formulas returning empty text.
Use VBA Evaluate to Find the Last Nonzero Row in Column Q
Calculate the last matching row directly from an Excel formula inside a VBA macro.
In Excel, select Developer > Visual Basic. If the Developer tab is hidden, enable it in Excel's ribbon customization settings.
Select Insert > Module and paste: Sub FindLastNonZero() Dim LastRowNonZero As Long LastRowNonZero = ActiveSheet.Evaluate("MAX((Q2:Q1000<>0)*ROW(Q2:Q1000))") MsgBox "Last nonzero row: " & LastRowNonZero End Sub
Activate the worksheet you want to search, then select Developer > Macros, choose FindLastNonZero, and click Run. The message box displays the row number.
In the module, replace both instances of Q2:Q1000 with the same range that covers your data, then run the macro again.

Work with Column Q Data in WPS Spreadsheets
WPS Office is a free, lightweight Office alternative with a familiar spreadsheet interface. Open compatible Excel workbooks to review and analyze column Q data as you move between office suites; VBA support depends on the WPS edition and configuration.

Frequently Asked Questions
What does the VBA expression return if every value is zero?
For a range containing only numeric zeros or blank cells, the expression returns 0, indicating that no nonzero row was found.
How do I search more rows in column Q?
In the VBA module, change both instances of Q2:Q1000 to the same larger range, such as Q2:Q5000, and run the macro again.
Which worksheet does the macro search?
The example uses ActiveSheet.Evaluate, so activate the worksheet containing your data before running the macro from Developer > Macros.
Can text or errors in column Q affect the result?
Yes. The example assumes numeric values or blank cells. Text, formulas returning empty text, and error values can produce unexpected results or cause the calculation to fail.




