# Sum if with and if function inside it macro excel

#### tuytuy

##### Board Regular
Hi,
i was trying to write a code that would sum if the cost of data consumption of non blackberry smartphone in national.
so i have a table where i get if the phone is a blackberry or not (column K) and if it is national or international (column N). Here is what i wrote but i get a compile error
Code:
``````'copy COST OF NON BLACKBERRY DATA NATIONAL
TotalIN = 0
ActiveWorkbook.Sheets("Section_14").Activate
Dim sumnbbItem As Variant
Tete = Array("Mobile Internet", _
"Internet On GSM")
For Each cstnbbItem In Tete
costnbbmn = costnbbmn + WorksheetFunction.SumIf(Range("K\$3:K\$1048576"), sumnbbItem , _
(If Range("N\$3:N\$1048576") = "GPRS national" Then), Range("J\$3:J\$1048576"))
Next
ActiveWorkbook.Sheets("SynthesisVSD").Activate
Range("A29").Value = "Cost of Non BlackBerry handset National data consumption:"
Range("B29").Value = sumbbmn
End If``````

### Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

#### tuytuy

##### Board Regular
Code:
``````'copy COST OF NON BLACKBERRY DATA NATIONAL

TotalIN = 0
ActiveWorkbook.Sheets("Section_14").Activate
Dim sumnbbItem As Variant
Tete = Array("Mobile Internet", _
"Internet On GSM")
For Each cstnbbItem In Tete
costnbbmn = costnbbmn + WorksheetFunction.SumIf(Range("K\$3:K\$1048576"), sumnbbItem, WorksheetFunction.If(Range("N\$3:N\$1048576"), "GPRS national"), Range("J\$3:J\$1048576"))
Next
ActiveWorkbook.Sheets("SynthesisVSD").Activate
Range("A29").Value = "Cost of Non BlackBerry handset National data consumption:"
Range("B29").Value = sumbbmn
End If``````

i've changed my code to the above and know i get a error saying wrong number of argument.

Replies
4
Views
398
Replies
2
Views
411
Replies
2
Views
277
Replies
2
Views
457

1,195,992
Messages
6,012,740
Members
441,724
Latest member
Aalbid

### 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.

### Which adblocker are you using?

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

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