Home » excel » excel – How to use a variable as criteria for the sumifs formula in vba

excel – How to use a variable as criteria for the sumifs formula in vba

Posted by: admin May 14, 2020 Leave a comment

Questions:

Can anybody please help me with the correction of the following code:

Dim Medium As String

Medium = "XYZ"

ActiveCell.FormulaR1C1 = "=SUMIFS(List2!C[8],List2!C[2],""=XYZ"",List2!C[11],""=prime"")"

I need to replace the ""=XYZ"" part of the code with the variable

How to&Answers:

Like this?

Dim Medium As String    
Medium = "XYZ"    
ActiveCell.FormulaR1C1 = "=SUMIFS(List2!C[8],List2!C[2]," & _
                         Chr(34) & _
                         Medium & _
                         Chr(34) & _
                         ",List2!C[11],""=prime"")"