Forum Discussion

hrh_dash's avatar
hrh_dash
Iron Contributor
Jun 24, 2022

How should i write the sumifs .formula vba so that the code runs smoothly

How should i write the SUMIFS macro code by using the .Formula method so that the SUMIFS will execute correctly?    With ws.Range("M2") .Formula = "=SUMIFS('C:\Users\hrhquek\Desktop\[calculate...
  • HansVogelaar's avatar
    HansVogelaar
    Jun 26, 2022

    hrh_dash 

    How about

        With ws.Range("M2")
            .NumberFormat = "#,##0.00"
            .Formula = "=SUMIFS($I:$I,$F:$F,"">60"",$G:$G, ""USD"")"
            .Value = .Value
        End With
    

    or

        With ws.Range("M2")
            .NumberFormat = "#,##0.00"
            .Value = Evaluate("=SUMIFS($I:$I,$F:$F,"">60"",$G:$G, ""USD"")")
        End With

    or

        With ws.Range("M2")
            .NumberFormat = "#,##0.00"
            .Value = Application.SumIfs(Range("I:I"), Range("F:F"), ">60", Range("G:G"), "USD")
        End With

Resources