Excel Guides

Using Seek in a Macro in Excel

Using Seek in a Macro in Excel

The Seek function can be used in a macro to search for a specific value in a range of cells. The function returns the address of the cell that contains the value that is being sought. If the value is not found, the function will return an error.

To use the Seek function, the syntax is:

Seek(value, range, [search order])

[search order] is an optional argument that specifies the order in which the cells in the range are to be searched. The default value is 1, which searches from top to bottom, left to right. If the value is 2, the cells are searched from bottom to top, right to left.

For example, suppose we have a range of cells with values in them, and we want to find the cell that contains the value 5. We could use this code:

Dim myAddress As String 
myAddress = Seek(5, Range("A1:C3"), 1) 
MsgBox myAddress

This would display a message box with the address of the cell that contains 5 (assuming it exists in the range). If there is no cell in the range with the value 5, then an error would be displayed.

Move beyond 

Excel

Get started with Causal today.
Build models effortlessly, connect them directly to your data, and share them with interactive dashboards and beautiful visuals.