user9459861
user9459861

Reputation: 15

SUMIFS in VBA formula using criteria

I am relatively new to Excel VBA script and am having trouble with the syntax quotes here on this line

ActiveSheet.Range("H" & EndRowH + 2).Formula = "=SUMIFS(H2:H &EndRowH & ,C1:C1000,&"">=""&lngStart&)"

Let me know if you need any other details.

Upvotes: 1

Views: 944

Answers (1)

user4039065
user4039065

Reputation:

  1. You had some basic string concatenation syntax errors.
  2. Both the criteria range and the sum range need to be the same number of rows.

    ActiveSheet.Range("H" & EndRowH + 2).Formula = "=SUMIFS(H2:H" & EndRowH & ", C2:C" & EndRowH & ", "">=" & lngStart &""")"
    
  3. Your original formula had the sum range start at H2 while the criteria range started at C1. While you can offset the sum range and the criteria range if necessary, they still have to be the same number of rows.

    ActiveSheet.Range("H" & EndRowH + 2).Formula = "=SUMIFS(H2:H" & EndRowH & ", C1:C" & EndRowH - 1 & ", "">=" & lngStart &""")"
    

Upvotes: 1

Related Questions