I got a code that is working OK at the moment. The problem is that this code is super slow. I was wondering if there might be a more efficient way to solve this problem.
I got two different workbooks (wb1 and wb2) with one sheet each (ws1 and ws2). The first workbook (wb1) which is my main workbook is about 7000 rows with 22 columns.
My second workbook (wb2) is instead 350000+ rows with 28 columns.

What do I want to do with my code? In my main document (wb1) then I want to get the lowest value in wb2 based on a criteria in column 5 (wb1). In other terms, its like =min(if(..)) in a excel array formula. Is there anyway that I can make this more efficient?


Dim wb1 As Workbook, wb2 as Workbook
Dim ws1, ws2

Dim vDataE As Variant, vDataO As Variant
Dim vE As Variant, vR As Variant, v As Variant, i As Long

vDataE = ActiveSheet.UsedRange.Columns(5).Value
vDataO = ActiveSheet.UsedRange.Columns(15).Value


With wb1.Sheets(ws1).Range("A1").CurrentRegion

    vE = .Columns(5).Value
    vR = .Columns(18).Value
    
    With CreateObject("Scripting.Dictionary")
    
        For i = 2 To UBound(vDataE, 1)
            If Not .exists(vDataE(i, 1)) Then
                .Item(vDataE(i, 1)) = vDataO(i, 1)
            Else
                If vDataO(i, 1) < .Item(vDataE(i, 1)) Then
                    .Item(vDataE(i, 1)) = vDataO(i, 1)
                End If
            End If
        Next
    
        For i = 2 To UBound(vE, 1)
            If .exists(vE(i, 1)) Then vR(i, 1) = .Item(vE(i, 1))
        Next i
    
    End With
    
    .Columns(18).Value = vR
    
End With