title: VBA Averageifs With Boolean Triggers
body: <p>I am trying to do averageif calculations based on these boolean triggers across 75,000 rows in an efficient manner.</p>
  
  <p>See below I have now tried to use the flag to calculate an average if but it's not working - can anyone suggest where I am going wrong? Also, is using Averageifs is to processor intensive and should I be using a different method? Thanks</p>
  
  <pre><code>Sub segment_trigger_returns()
  Application.ScreenUpdating = False
  Dim segment_trigger As Boolean
  Dim data_set As Variant
  data_set = Range("A4:AV75617")
  alpha_1y = Range("S4:S759617")
  Dim i As Long
  For i = 2 To UBound(data_set, 1)
  company_name_curperiod = data_set(i, 3)
  company_name_prevperiod = data_set(i - 1, 3)
  segments_curperiod = data_set(i, 10)
  segments_prevperiod = data_set(i - 1, 10)
  If company_name_curperiod = company_name_prevperiod And segments_curperiod &lt;&gt; segments_prevperiod Then
  segment_trigger = True
  Else: segment_trigger = False
  End If
  Next i
  Sheets("Control").Range("K6") = Application.WorksheetFunction.AverageIfs(alpha_1y, segment_trigger = True)
  Application.ScreenUpdating = True
  End Sub
  </code></pre>