Code VBA countif avec plusieur conditions

Voilà je suis en train d'écrire un code qui ferai le total de communication national et ensuit le total de communications international.

La partie national fonctionne parfaitement mais la partie international non, et je n'arrive pas à voir pourquoi.

Je crois que le problème est due au faite que j'ai besoin d'inclure plusieurs argument dans pour les communications internationales.

Voici mon code:

'Copy COST FOR NATIONAL CALLS

ActiveWorkbook.Sheets("Sheet6").Activate
Dim LastRow As Long, National As Double
  Const LookupType As String = "Communications nationales"
  LastRow = Cells(Rows.Count, "O").End(xlUp).Row
  National = WorksheetFunction.SumIf(Range("O2:O" & LastRow), LookupType, Range("R2:R" & LastRow))
ActiveWorkbook.Sheets("SynthesisVSD").Activate
Range("C6:C7").NumberFormat = "0.00"
Range("A8").Value = "Total cost of National Communications"
Range("B8").Value = "Gross cost : "
Range("C8").Value = National
cnp = (National * 37) / 100
Range("B9").Value = "Net cost (-37%): "
Range("C9").Value = National - cnp
Range("C8:C9").Style = "Currency"

'Copy COST FOR INTERNATIONAL CALLS

 TotalIN = 0
 ActiveWorkbook.Sheets("Sheet6").Activate
Dim LookupType As Variant, vItem As Variant
LastRow = Cells(Rows.Count, "O").End(xlUp).Row
LookupType = Array("Communications internationales", _
                  "Communications effectuées a l'étranger (ROAMING)", _
                  "Communications recues a l'étranger (ROAMING)")
For Each vItem In LookupType
  National = National + WorksheetFunction.SumIf(Range("O2:O" & LastRow), LookupType, Range("R2:R" & LastRow))
Next
ActiveWorkbook.Sheets("SynthesisVSD").Activate
Range("A4").Value = "Total cost of International Communications"
Range("B4").Value = National

Je reçois une erreur : Duplicate declaration in current scope

Bonjour

Ton fichier serait plus utile

Pour ton message d'erreur, tu as déclaré 2 fois LookupType

Const LookupType As String = "Communications nationales"
Dim LookupType As Variant

Oui j'avais remarqué aussi mais je quand j'essay de le changé je recois toujours un erreur.

Quand j'essaye de le changer je recois un un message disant: Expected: Identifier

Bonjour

Banzai64 a écrit :

Ton fichier serait plus utile

Dans ton code

For Each vItem In LookupType
  National = National + WorksheetFunction.SumIf(Range("O2:O" & LastRow), LookupType, Range("R2:R" & LastRow))
Next

A la place de LookupType cela ne serait pas vltem ?

Le problème est au niveau de LookupType:

Dim LookupType As Variant, vItem As Variant

Mais je ne sais pas quoi mettre à la place

Bonjour

Banzai64 a écrit :

Ton fichier serait plus utile

tuytuy a écrit :

Mais je ne sais pas quoi mettre à la place

Utilises ce que tu veux

Dim Toto As Variant, vItem As Variant
LastRow = Cells(Rows.Count, "O").End(xlUp).Row
Toto = Array("Communications internationales", _
                  "Communications effectuées a l'étranger (ROAMING)", _
                  "Communications recues a l'étranger (ROAMING)")
For Each vItem In Toto 
  National = National + WorksheetFunction.SumIf(Range("O2:O" & LastRow), vItem , Range("R2:R" & LastRow))
Next

YEAAAA ca fonctionne ! merci beaucoup,

désolé pour les question stupid je vien de commencé vba.

Rechercher des sujets similaires à "code vba countif conditions"