Skip to content

Lookup.cs

Avrigeanu Laurian edited this page Apr 12, 2023 · 1 revision

Lookup(object sheet, string lookupValue, string lookupRange, string resultRange, XlFindLookIn lookIn = XlFindLookIn.xlValues, XlLookAt lookAt = XlLookAt.xlWhole, XlSearchOrder searchOrder = XlSearchOrder.xlByRows, XlSearchDirection searchDirection = XlSearchDirection.xlNext, bool matchCase = false)

Parameters

  • sheet: The name of the worksheet in which the lookup should be performed.
  • lookupValue: The value to look up in the lookupRange.
  • lookupRange: The range to search for the lookupValue.
  • resultRange: The range containing the values to return.
  • lookIn: An optional parameter specifying where to look for the lookupValue (default: XlFindLookIn.xlValues).
  • lookAt: An optional parameter specifying whether to look for an exact match or a partial match (default: XlLookAt.xlWhole).
  • searchOrder: An optional parameter specifying the order in which to search the range (default: XlSearchOrder.xlByRows).
  • searchDirection: An optional parameter specifying the direction in which to search the range (default: XlSearchDirection.xlNext).
  • matchCase: An optional parameter specifying whether to perform a case-sensitive match (default: false).

Returns

  • An object containing the value of the cell in the resultRange that corresponds to the lookupValue.

Remarks

  • This method searches for the lookupValue in the specified lookupRange on the specified worksheet and returns the corresponding value from the resultRange. If the lookupValue is not found in the lookupRange, an exception is thrown.
  • The optional parameters lookIn, lookAt, searchOrder, searchDirection, and matchCase can be used to fine-tune the search behavior.
  • This method should only be used with Excel workbooks, as it uses the Excel Interop library to perform the lookup.
  • The method releases the Excel objects created during the search process, which is important to avoid memory leaks.
Clone this wiki locally