I have an Excel sheet where values are in the column A and B. Column A has duplicate values. I need to find the smallest value in column B for a given value in column A, and copy that value into a new column. How can I do this?
Asked
Active
Viewed 165 times
1 Answers
0
If you want to do this in VBA, you could use a Scripting.Dictionary
, with each iteration checking if the new value is less than the previous value for a given key.
Then, since the keys and values are exposed on the Dictionary as arrays, you can simply write the keys/values to a destination range.
Alternatively, you could issue the following SQL statement against the Excel worksheet:
SELECT Field1, MIN(Field2)
FROM [$Sheet1]
GROUP BY Field1
Presumably you would do this via an ADO or DAO Recordset, which you can paste into the destination range using the CopyFromRecordset
method.

Zev Spitz
- 13,950
- 6
- 64
- 136