Skip to content

Range & lookup functions

This group contains 14 functions that work on ranges: extended lookups (one-way, two-way, multi-result, across every worksheet), filtering arrays and extracting unique values, summing or counting by fill colour or by visible rows, and hiding rows automatically by condition.

The examples below use a semicolon ; to separate arguments (Excel running on a Vietnamese regional format). If your Excel uses the English (US) format, type a comma , instead of ;.

Quick reference:

FunctionPurpose
dvdXlookupExtended lookup with error handling and approximate match.
dvdELookupReturn the result of the last matching row.
dvdMCLookupWrite every matching row, across several columns, into an output range.
dvdMVLookupReturn every matching value from a column offset to the lookup column.
dvdTableLookupTwo-way lookup by row header and column header.
dvdLookupAllSheetsLook a value up across all worksheets of the workbook.
dvdUniqueReturn an array of the unique values of a range.
dvdUniqueVReturn the unique values, writing the remainder into an output range.
dvdUnique2DArrayKeep the unique rows of an array based on one key column.
dvdFilter2DArrayFilter a two-dimensional array on one column.
dvdSumVisibleSum the visible cells, skipping hidden rows and columns.
dvdSumIfColorSum the cells whose fill colour matches a sample cell.
dvdCountIfColorCount the cells whose fill colour matches a sample cell.
dvdAutoHideHide the rows that fail a condition and renumber the rest.

dvdXlookup

Looks a value up in the lookup range and returns the matching value from the result range, with optional fallbacks for "not found" and "error".

Syntax:

=dvdXlookup(LookupValue; LookupArray; ReturnArray; [IfNotFound]; [IfError]; [MatchMode])
ParameterRequiredDescription
LookupValueYesValue to look for inside LookupArray.
LookupArrayYesRange in which the search is performed.
ReturnArrayYesRange the result is taken from.
IfNotFoundNoValue returned when nothing matches; #N/A when omitted.
IfErrorNoValue returned on error; #N/A when omitted.
MatchModeNo0 = exact (default), -1 or 1 = approximate, like XLOOKUP.

Example:

=dvdXlookup(A6; 'Đơn giá'!$A$5:$A$500; 'Đơn giá'!$E$5:$E$500; "Chưa có đơn giá"; "Lỗi dữ liệu"; 0)
// → 1,850,000 (unit rate of the work code in A6)

=dvdXlookup(D6; $H$5:$H$20; $I$5:$I$20; ""; ""; 1)
// → the haulage factor of the nearest distance band not exceeding D6

Notes

  • The function always tries an exact match first; the approximate pass only runs when nothing matched and MatchMode is not 0.
  • Approximate matching works on numeric data only: -1 takes the smallest value greater than or equal to the lookup value, 1 takes the largest value less than or equal to it.

dvdELookup

Searches from the bottom up and returns the result of the last match — useful when a work code appears several times and you need the most recent record.

Syntax:

=dvdELookup(LookupValue; LookupRange; ResultRange)
ParameterRequiredDescription
LookupValueYesValue to look for.
LookupRangeYesRange containing the value to look for.
ResultRangeYesRange containing the result.

Example:

=dvdELookup(A6; $B$5:$B$300; $F$5:$F$300)
// → the quantity of the latest acceptance record for work code A6

Notes

  • When nothing matches, the function returns the text Không tìm thấy kết quả ("no result found").
  • Both ranges should have the same number of rows, because the result is taken by matching position.

dvdMCLookup

Returns every row matching the lookup value, with all of its columns, written into an output range on the worksheet.

Syntax:

=dvdMCLookup(ReturnCols; LookupColIndex; LookupValue; outputRange)
ParameterRequiredDescription
ReturnColsYesColumns containing the values to return.
LookupColIndexYesIndex of the lookup column, counted from 1 inside ReturnCols.
LookupValueYesValue to look for.
outputRangeYesTarget range where the results are written.

Example:

=dvdMCLookup($A$5:$F$500; 2; $H$3; $H$6:$M$40)
// → "Done", and every row whose item code equals H3 is written into H6:M40

Notes

  • The formula cell only shows Done; the data goes into outputRange, which is cleared before writing — leave a large enough empty area.
  • The function is volatile: Excel recalculates it whenever anything in the workbook changes.
  • When no row matches, the function returns #N/A.

dvdMVLookup

Returns every matching value from a column offset to the lookup column: the first hit appears in the formula cell, the remaining hits are written into the output range.

Syntax:

=dvdMVLookup(LookupValue; LookupCol; OffsetCol; outputRange)
ParameterRequiredDescription
LookupValueYesValue to look for.
LookupColYesColumn containing the value to look for.
OffsetColYesNumber of columns to the right of LookupCol holding the returned value.
outputRangeYesTarget range for the second and later values (for Excel 2019/2016 without dynamic arrays).

Example:

=dvdMVLookup($H$3; $B$5:$B$500; 4; $J$4:$J$40)
// → the first quantity for work code H3; the remaining quantities go into J4:J40

Notes

  • The output range is cleared before writing; pick an empty area outside the data table.
  • The function is volatile: Excel recalculates it whenever anything in the workbook changes.

dvdTableLookup

Two-way lookup: returns the value at the intersection of the row and the column identified by their headers.

Syntax:

=dvdTableLookup(LookupRowValue; LookupColumnValue; TableRange)
ParameterRequiredDescription
LookupRowValueYesValue to find in the first column of the table.
LookupColumnValueYesValue to find in the first row of the table.
TableRangeYesData table, including both row and column headers.

Example:

=dvdTableLookup("D16"; "Cấp bền B22.5"; $A$5:$H$30)
// → 1.284 (norm looked up by rebar diameter and concrete grade)

Notes

  • When the row or the column header is not found, the function returns the text Không tìm thấy kết quả ("no result found").

dvdLookupAllSheets

Looks a value up across every visible worksheet of the workbook and returns the value from the requested column.

Syntax:

=dvdLookupAllSheets(lookupValue; lookup_column; result_column)
ParameterRequiredDescription
lookupValueYesValue to look for.
lookup_columnYesNumber of the column containing the value to look for (column A is 1).
result_columnYesNumber of the column containing the value to return.

Example:

=dvdLookupAllSheets(A6; 2; 6)
// → the quantity in column F of the row whose work code is A6, searched on every quantity sheet

Notes

  • The worksheet holding the formula and any hidden worksheets are skipped; when nothing matches the function returns #N/A.
  • Columns are counted as worksheet columns, not as positions inside a range.

dvdUnique

Returns a one-column array holding the unique values of a range.

Syntax:

=dvdUnique(rng)
ParameterRequiredDescription
rngYesInput data range.

Example:

=dvdUnique($B$6:$B$500)
// → the list of distinct items: Móng, Cột, Dầm, Sàn

Notes

  • The function returns an array: Excel 365/2021 spills it automatically; on Excel 2019 and earlier select the target range and press Ctrl+Shift+Enter, or use dvdUniqueV.
  • Values are compared case-insensitively.

dvdUniqueV

Returns the first unique value in the formula cell and writes the remaining unique values into the output range — made for Excel versions without dynamic arrays.

Syntax:

=dvdUniqueV(inputRange; outputRange)
ParameterRequiredDescription
inputRangeYesRange holding the values to deduplicate.
outputRangeYesRange where the remaining unique values are written (for Excel 2019/2016).

Example:

=dvdUniqueV($B$6:$B$500; $H$7:$H$40)
// → "Móng" in the formula cell; the other items are written into H7:H40

Notes

  • The output range is cleared before writing.
  • The function is volatile: Excel recalculates it whenever anything in the workbook changes.
  • Empty cells in the source range are skipped.

dvdUnique2DArray

Keeps the unique rows of a two-dimensional array based on one key column.

Syntax:

=dvdUnique2DArray(sArray; colIndex; HasTitle)
ParameterRequiredDescription
sArrayYesInput two-dimensional array.
colIndexYesIndex of the key column, counted from 1.
HasTitleYesTRUE when the data has a header row.

Example:

=dvdUnique2DArray($A$5:$F$500; 2; TRUE)
// → the subcontractor table with only the first occurrence of each code

Notes

  • The function returns a two-dimensional array: Excel 365/2021 spills it; older versions need it entered as an array formula with Ctrl+Shift+Enter.
  • With HasTitle set to TRUE the header row is always kept at the top of the result.

dvdFilter2DArray

Filters a two-dimensional array on a condition applied to one column and returns the matching rows.

Syntax:

=dvdFilter2DArray(DataArray; ColumnIndex; Criteria; HasTitle)
ParameterRequiredDescription
DataArrayYesTwo-dimensional array holding the data to filter.
ColumnIndexYesIndex of the column the criteria apply to, counted from 1.
CriteriaYesFilter criteria, for example ">5", "abc", "abc*".
HasTitleYesTRUE when the data has a header row.

Example:

=dvdFilter2DArray($A$5:$F$500; 6; ">0"; TRUE)
// → the table reduced to work items with a quantity greater than zero

=dvdFilter2DArray($A$5:$F$500; 2; "BT*"; TRUE)
// → the rows whose work code starts with "BT"

Notes

  • The function returns a two-dimensional array: Excel 365/2021 spills it; older versions need it entered as an array formula with Ctrl+Shift+Enter.
  • Criteria accept comparison operators (">5", ">=2", "<>0") and wildcards (*, ?).

dvdSumVisible

Sums the values of the visible cells, skipping any cell in a hidden row or column.

Syntax:

=dvdSumVisible(SumRng)
ParameterRequiredDescription
SumRngYesRange whose visible cells are summed.

Example:

=dvdSumVisible($F$6:$F$500)
// → the total amount of the rows still visible after filtering by item

Notes

  • The function is volatile: Excel recalculates it whenever anything changes, so avoid using it hundreds of times on a very large sheet.
  • Cells hidden by AutoFilter, hidden manually or hidden by dvdAutoHide are all skipped.

dvdSumIfColor

Sums the cells whose fill colour matches the fill colour of a sample cell.

Syntax:

=dvdSumIfColor(rngSum; rngCellColor)
ParameterRequiredDescription
rngSumYesRange whose values are summed.
rngCellColorYesCell whose fill colour is used as the condition.

Example:

=dvdSumIfColor($F$6:$F$500; $H$3)
// → the total quantity of the rows filled with the same colour as H3 (for example the "variation" mark)

Notes

  • Changing a fill colour does not trigger a recalculation; press Ctrl+Alt+F9 after recolouring to refresh the result.
  • The comparison uses the fill colour applied directly to the cell, not colours produced by conditional formatting.

dvdCountIfColor

Counts the cells in a range whose fill colour matches the fill colour of a sample cell.

Syntax:

=dvdCountIfColor(RangeToCount; ReferenceCell)
ParameterRequiredDescription
RangeToCountYesRange of cells to count.
ReferenceCellYesCell whose fill colour is used as the reference.

Example:

=dvdCountIfColor($B$6:$B$500; $H$4)
// → 12 (number of items flagged as behind schedule)

Notes

  • Changing a fill colour does not trigger a recalculation; press Ctrl+Alt+F9 after recolouring to refresh the result.
  • The comparison uses the fill colour applied directly to the cell, not colours produced by conditional formatting.

dvdAutoHide

Hides the rows that fail the condition and renumbers the rows that stay visible.

Syntax:

=dvdAutoHide(Target; Cells; Conditions; [OrdersRange]; [Title])
ParameterRequiredDescription
TargetYesRange of rows covered by the hide/show operation.
CellsYesRange holding the values compared against the conditions.
ConditionsYesCondition, for example "0", ">=2", "<>0"; several conditions can be supplied as a range.
OrdersRangeNoRange that is renumbered after hiding.
TitleNoText shown in the formula cell, DVDAutoHide by default.

Example:

=dvdAutoHide($A$6:$A$500; $F$6:$F$500; "<>0"; $A$6:$A$500; "Ẩn dòng khối lượng 0")
// → keeps the rows with a non-zero quantity, hides the rest and renumbers them consecutively

Notes

  • A row stays visible when at least one of its cells in Cells satisfies every condition; all other rows are hidden.
  • Hiding runs after Excel finishes calculating, so the result may appear one beat later than the formula entry.
  • The function is volatile: Excel recalculates it whenever anything in the workbook changes.
  • Put the formula in a cell outside Target so that it is not hidden along with the rows.

Released under DVDAddin License.