VBA & Macro Problems

Return the Row of the Smallest Value in Excel with VBA

Emma BrownEmma Brown Nov 27, 2026 870 views

Question details

Return the worksheet row of the first occurrence of the smallest value in column H using VBA.

Return the Row of the Smallest Value in Excel with VBA
Product
Microsoft Excel
Device & OS
not provided
Scenario
A VBA function searches column H on a worksheet identified by name.
Observed behavior
The current function returns the minimum value, but the desired result is the worksheet row containing its first occurrence.
Before you start

Make sure the target worksheet exists and column H contains at least one numeric value without cell errors. Open the workbook in Excel and enable its macros if prompted and you trust the file.

Solution 1Recommended

Use MIN and MATCH to return the worksheet row

Use this function to find the first occurrence of the minimum numeric value in column H.

MIN finds the smallest numeric value, and MATCH with a match type of 0 returns its first position in the range. Adding the range's starting row and subtracting 1 converts that position to a worksheet row.

1
Open the VBA editor

In Excel, select Developer > Visual Basic, then choose Insert > Module.

2
Add the function

Paste this code into the module: Function Find_Smallest_Value(strSheetName As String) As Variant Dim rng As Range Set rng = ThisWorkbook.Worksheets(strSheetName).Range("H:H") If Application.WorksheetFunction.Count(rng) = 0 Then Find_Smallest_Value = CVErr(xlErrNA) Exit Function End If Find_Smallest_Value = rng.Row + Application.WorksheetFunction.Match( _ Application.WorksheetFunction.Min(rng), rng, 0) - 1 End Function

3
Call the function

Call Find_Smallest_Value("Sheet1") from your VBA code, replacing Sheet1 with the target worksheet name. The function returns the worksheet row, or a #N/A error value if the range has no numeric values.

4
Save the workbook

Select File > Save As and choose Excel Macro-Enabled Workbook (*.xlsm) to keep the VBA code.

Use MIN and MATCH to return the worksheet row
Searching a smaller range: You can replace Range("H:H") with a range such as Range("H5:H100"). The rng.Row offset in the function ensures the result is still the worksheet row, not just the position within that range.
Free Microsoft Office alternative

Find minimum-value rows in WPS Spreadsheets

WPS Office is a free, lightweight Office alternative with a familiar interface and support for Excel formats, making it easy to move spreadsheet work between applications. In WPS Spreadsheets, you can use a MIN and MATCH formula to find a minimum-value row without relying on the Excel VBA function.

Find the first minimum-value row with spreadsheet formulasOpen and edit Microsoft Excel XLSX filesWork in a familiar spreadsheet interfaceUse a free, lightweight Office alternative
microsoft office alternative - wps office

Frequently Asked Questions

What happens if the minimum value appears more than once?

MATCH with a match type of 0 returns the position of the first matching minimum value, so the function returns the first occurrence's worksheet row.

Why did Application.Find(minimum, rng).Row produce an error?

Application.Find is not the Range.Find method and does not return a cell Range object whose Row property you can read. Use MIN and MATCH as shown, or use the Range.Find method separately.

How do I get the worksheet row when searching H5:H100?

Set rng to Range("H5:H100") and use rng.Row + MATCH result - 1. MATCH alone returns a position relative to H5, not the worksheet row.

Can I find the row without VBA?

In Excel or WPS Spreadsheets, enter =MATCH(MIN(H:H),H:H,0) in a cell. For a full-column range, the returned position is also the worksheet row. Ensure column H contains numeric data and no cell errors.