Sumif in Vba with more than one criterion

xmiguelx

New Member
Joined
Jan 4, 2020
Messages
12
Office Version
  1. 2010
Platform
  1. Windows
Hello people,

I need help.

I am trying to do a balance check, I have tried in several ways and I cannot continue.
Today I am using the formula and would like to switch to Vba.

Below the formula I am using in column V to the last line with information in column D.

FORMULA: =TRUNC(IF(G4="ATIVA";IF(M4="CREDIT";L4-SUMIFS(L:L;S:S;D4;G:G;"ATIVA");0);0);2)

Below the formula, I am writing in VBA and it is not working.:

VBA Code:
Sub CALCULATE_BALANCE()

    Application.ScreenUpdating = False
    Application.DisplayStatusBar = False
    Application.Calculation = xlCalculationManual

linha1 = 3

With Sheets("CONTROL")
    For Cont = 4 To Cells(Rows.Count, 4).End(xlUp).Row
        
        Set rng1 = .Cells(linha1 + 1, 4)
        
        ActiveSheet.Cells(linha1 + 1, 22).Value = WorksheetFunction.SumIfs(.Range("L4:L" & Cont), .Range("G4:G" & Cont), "ATIVA", .Range("M4:M" & Cont), "CREDIT")
        
        linha1 = linha1 + 1
        
        Next Cont
    End With
    
    
    Application.Calculation = xlCalculationAutomatic
    Application.DisplayStatusBar = True
    Application.ScreenUpdating = True
    
End Sub

If anyone can help me correct or reconstruct my VBA formula, I appreciate it.

Tks

EXEMPLE
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
VBA Code:
With Sheets("CONTROL")
    With .Range("V4:V" & .Range("D" & Rows.Count).End(xlUp).Row)
        .Formula = "=TRUNC(IF(AND(G4=""ATIVA"";M4=""CREDIT"");L4-SUMIFS(L:L;S:S;D4;G:G;""ATIVA"");0);2)"
        .Value = .Value
    End With
End With
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,700
Members
448,979
Latest member
DET4492

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top