In the first row i have a list of elements and at subsequent rows random numbers under each element and i want to match the element with the max of each row, all the max values though not just the first one. This is achieved by the following function =IF(COLUMNS(F2:$F2)<=$E2,INDEX($A$1:$C$1,SMALL(IF($A2:$C2=$D2,COLUMN($A2:$C2)),COLUMNS(F2:$F2))),"") and dragged to the right the desired result is shown in the yellow cells

The following code is giving a type mismatch error and my vba is not so deep to understand why.

VBA Code:

```
For i=2 to something
For j=1 to 3
Cells(count, j + 8) = WorksheetFunction.Index(Range(Cells(1, 1), Cells(1, 3)), WorksheetFunction.Small(IIf(Range(Cells(i, 1), Cells(i, 3)).Value = Cells(i, 4), Range(Cells(i, 1), Cells(i, 3)).Column, ""), Range(Cells(count, j)).Column))
Next j
Next i
```

Can you please fix the previous code or suggest anything that does the same thing?

Thanks a lot