I have table with Product name and Batch No. The product name is selected from a combo box frmmaster.cmbproduct. Each product has a unique combination for batch number and the last digit of the batch number changes. Sample table
The next batch number of a particular product is the last batch number +1. I have used aggregate function in excel to find the highest batch number. But the same aggregate function is throwing error in VBA.
Aggregate function for excel is =AGGREGATE(14,4,($B$2:$B$2000 =N12)*$C$2:$C$2000,1) where in N12 I am putting product name. Column B contains product name and column C contains batch number
Dim res As Long
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Database")
With sh
'On Error Resume Next
res = WorksheetFunction.Aggregate(14, 4, ("R2C2:R2000C2" = FrmMaster.CmbProduct.Value) * "R2C3:R2000C3", 1)
MsgBox (res)
End With
The above code is throwing type mismatch error
I have changed the variable to hold value to variant and string but no result.
res = Evaluate("=AGGREGATE(14,4,($B$2:$B$2000 =""" & FrmMaster.CmbProduct.Value & """)*$C$2:$C$2000,1)")
:-) - T.M.