I have an array of product specs, declared as type Variant. The 5th column is the price. I am trying to find product pairs according to a set of criteria, including pairs both priced above 6. I am getting runtime error 13, type mismatch in the colored part of below code excerpt:
If i remove all references to min (i.e. I relax this condition), the code works. I have tried declaring min as type integer as well (which column 5 is) but I'm getting the same error.
Rich (BB code):
Dim ws As Worksheet: Set ws = ActiveSheet
Dim rg As Range: Set rg = ws.Range("B2:F4110")
Dim rCount As Integer: rCount = rg.Rows.count
Dim rOffset As Integer: rOffset = rg.Row - 1
Dim linenum As Integer
Dim spread As Variant
Dim ri As Integer
Dim rj As Integer
Dim min As Variant
Dim Data() As Variant: Data = rg.Value
linenum = 2
Range("K:N").ClearContents
For ri = 1 To rCount - 1
For rj = ri + 1 To rCount
min = IIf(Data(ri, 5) < Data(rj, 5), Data(ri, 5), Data(rj, 5))
If Data(ri, 1) = Data(rj, 1) _
And Data(ri, 2) = Data(rj, 2) _
And min >= 6 _
And Abs(Data(ri, 5) - Data(rj, 5)) = 2 Then
Cells(linenum, 11).Value = Data(ri, 1)
Cells(linenum, 12).Value = Data(ri, 3)
Cells(linenum, 13).Value = Data(ri, 4)
If Data(ri, 5) < Data(rj, 5) Then
spread = Data(rj, 3) - Data(ri, 3)
Else
spread = Data(ri, 3) - Data(rj, 3)
End If