Return row number of a specific value
To return a row number of a specific value we need to apply the Excel MATCH function
Example: Return row number of a specific value
=MATCH(D5,B:B,0)
|
The formula uses the Excel MATCH function to return the row number in column B that captures the value of "Cereal". The formula will only return the row of the first occurrence of the specific value.
|
Dim ws As Worksheet
ws.Range("E5").Value = Application.WorksheetFunction.Match(ws.Range("D5"), ws.Range("B:B"), 0)
End Sub
Worksheets: The Worksheets object represents all of the worksheets in a workbook, excluding chart sheets.
Range: The Range object is a representation of a single cell or a range of cells in a worksheet.
Worksheet Name: Have a worksheet named Analysis.
Specific Value: Have the specific value that you are searching for in cell ("D5").
ADJUSTABLE PARAMETERS
Output Range: Select the output range by changing the cell reference ("E5") in the VBA code to any cell in the worksheet, that doesn't conflict with the formula.
Column Reference: Select the column(s) that you are searching through for the specific value by changing the column reference ("B:B") in the VBA code to any column in the worksheet, that doesn't conflict with the formula.
Specific Value: Select the specific value that you are searching for by changing the cell reference ("D5") in the VBA code to any cell that contains the specific value that you wan to search for in the Analysis worksheet that doesn't conflict with the formula. You can also change the value that is held in cell ("D5") to any specific value that you are looking to return the row number for.
To return a row number of a specific value we need to apply the Excel MATCH function.
=MATCH(lookup_value, column_ref, 0)
lookup_value: The value that you intend to search for and return the row number.
column_ref: The column from which to lookup the specific value.
ADDITIONAL NOTES
Note 1: Given the formula uses the Excel MATCH function, the specific value is case-sensitive.
Note 2: If the formula cannot locate the specified value from the selected range it will return an #NA error.