VBA Code:
Sub TechProc() Dim i As Variant Dim row1 As Variant, rowx As Variant Dim var_low As Variant, var_hig As Variant Dim validPeriods As Variant, UC3OnOff As Variant Dim db As String, variable As String, datedb Dim dateI As String, dateF As String Dim validPeriods_name As Variant Dim UC3OnOff_name As Variant Dim str1 As Variant, str2 As Variant, str3 As Variant Dim str4 As Variant, str5 As Variant, str6 As Variant Dim str As String row1 = 15 rowx = 800 str = "" For i = row1 To rowx 'Dates criteria db = "rd_process" dateI = "J$4" dateF = "J$5" datedb = db & "[pr.dates]" str1 = datedb & ";" & Chr(34) & ">=" & Chr(34) & "&" & dateI & ";" & datedb & ";" & Chr(34) & "<=" & Chr(34) & "&" & dateF str4 = "(" & datedb & ">=" & dateI & ")*(" & datedb & "<=" & dateF & ")" 'Lower and upper limits for each parameter var_low = "$G" & i var_hig = "$H" & i variable = db & "[" & Range("$E" & i).Value & "]" str2 = variable & ";" & var_low & ";" & variable & ";" & var_hig str5 = "(" & variable & ">=" & var_low & ")*(" & variable & "<=" & var_hig & ")" 'Valid Periods and UC3 ON/OFF validPeriods = 1 validPeriods_name = db & "[pr.Valid_Periods]" UC3OnOff = "J$9" UC3OnOff_name = db & "[pr.UC3_aa.a_00xx.ONOFF]" str3 = validPeriods_name & ";" & validPeriods & ";" & UC3OnOff_name & ";" & UC3OnOff str6 = "(" & validPeriods_name & "=" & validPeriods & ")*(" & UC3OnOff_name & "=" & UC3OnOff & ")" If Range("D" & i).Value = "avg" And Range("I" & i).Value <> Empty Then Range("J" & i).Value = ***"+AverageIfs(" & variable & ";" & str1 & ";" & str2 & ";" & str3 & ")"*** Range("J" & i).Activate ActiveCell.FormulaR1C1 = *"+AverageIfs(" & variable & ";" & str1 & ";" & str2 & ";" & str3 & ")"* ElseIf Range("D" & i).Value = "stdev" And Range("I" & i).Value <> Empty Then Range("J" & i).Value = "+stdev(if(" & str4 & "*" & str5 & "*" & str6 & ";" & variable & "))" Range("J" & i).Activate ActiveCell.Replace What:="'", Replacement:="" End If Next