sumif with multiple criteria

Akbarov

Active Member
Joined
Jun 30, 2018
Messages
347
Office Version
  1. 365
Platform
  1. Windows
Hey community,

i use following VBA

Code:
Sub BonaquaASM1()Application.ScreenUpdating = False
    Dim Markets As Worksheet, lr As Long
    lr = Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
    Set Markets = Sheets("sheet4")
    Sheets("DATA").Range("A1:A" & lr).Name = "run"
    Sheets("DATA").Range("L1:L" & lr).Name = "sifaris"
    Sheets("DATA").Range("M1:M" & lr).Name = "inted"
    Sheets("DATA").Range("E1:E" & lr).Name = "teri"
    Sheets("DATA").Range("H1:H" & lr).Name = "asm"
    Sheets("sheet4").Range("AP1:AP" & lr).Name = "ayi"
    Sheets("sheet4").Cells(1, 44).Name = "asma"
    Markets.Range("c1:c" & lr).Name = "MARKET"
    With Sheets("DATA").Cells(2, "BB")
    .FormulaArray = "=sum(if((isnumber(match(run,market,0)))*(sifaris>0)*(urun<>"""")*(not(isnumber(match(teri,ayi,0))))*(isnumber(match(asm,asma,0))),inted))"
    .Value = .Value
End With
End Sub

formula was working fine, i only added last part
Code:
*(isnumber(match(asm,asma,0)))
now i get 0 result. what am i doing wrong? i need it to sum if asm=asma
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
The name "urun" is not defined in the code like the other names.

Code:
.FormulaArray = "=sum(if((isnumber(match(run,market,0)))*(sifaris>0)*([COLOR=#ff0000]urun[/COLOR]<>"""")*(not(isnumber(match(teri,ayi,0))))*(isnumber(match(asm,asma,0))),inted))"
    .Value = .Value
 
Upvote 0
i'v edited that, but thats not solved problem, can you help me to change this formula to SUMIFS?
 
Upvote 0
In this line you are not indicating which sheet.


Code:
[COLOR=#333333]lr = Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row[/COLOR]

You should have 2 variables one for sheet4 and one for "data" sheet

Code:
Sub BonaquaASM1()
  Application.ScreenUpdating = False
  Dim Markets As Worksheet, [B][COLOR=#0000FF]lr1 [/COLOR][/B]As Long, [B][COLOR=#FF0000]lr2[/COLOR][/B] As Long
  Set Markets = Sheets("sheet4")
  [B][COLOR=#0000ff]lr1 [/COLOR][/B]= Sheets("[COLOR=#008000]sheet4[/COLOR]").Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
  [B][COLOR=#ff0000]lr2 [/COLOR][/B]= Sheets("[COLOR=#b22222]DATA[/COLOR]").Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
  Sheets("DATA").Range("A1:A" & [B][COLOR=#FF0000]lr2[/COLOR][/B]).Name = "run"
  Sheets("DATA").Range("L1:L" & [B][COLOR=#FF0000]lr2[/COLOR][/B]).Name = "sifaris"
  Sheets("DATA").Range("M1:M" & [B][COLOR=#FF0000]lr2[/COLOR][/B]).Name = "inted"
  Sheets("DATA").Range("E1:E" & [B][COLOR=#FF0000]lr2[/COLOR][/B]).Name = "teri"
  Sheets("DATA").Range("H1:H" & [B][COLOR=#FF0000]lr2[/COLOR][/B]).Name = "asm"
  Sheets("sheet4").Range("AP1:AP" & [B][COLOR=#0000FF]lr1[/COLOR][/B][COLOR=#0000ff])[/COLOR].Name = "ayi"
  Sheets("sheet4").Cells(1, 44).Name = "asma"
  Markets.Range("c1:c" & [B][COLOR=#0000FF]lr1[/COLOR][/B]).Name = "MARKET"
  With Sheets("DATA").Cells(2, "BB")
    .FormulaArray = "=sum(if((isnumber(match(run,market,0)))*(sifaris>0)*(run<>"""")*(not(isnumber(match(teri,ayi,0))))*(isnumber(match(asm,asma,0))),inted))"
    .Value = .Value
  End With
End Sub
 
Upvote 0
Thanks for reply, i tryed your work. it only works when i delete
Code:
(isnumber(match(asm,asma,0)))
this part
 
Upvote 0
It works with my test data, I would have to review your data.

You could upload a copy of your file to a free site such www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. If the workbook contains confidential information, you could replace it with generic data.
 
Upvote 0
yes it contains confidential information , asma is numerical values ( sales persons ID : 370 in this case ) , and asm contains full list with all ids, i need VBA to sum if 370 is on list

i would be really gratefull if you can help me to change this formula to SUMIFS if possible, thisone seems very complicated for me
 
Last edited:
Upvote 0
it works, problem was because i took data from server, numbers saved as texts, i fixed it now it works fine, thank you very much
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,242
Members
452,623
Latest member
russelllowellpercy

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