Hi,
I've tried to right a code to simulate the if function by defining an array.
But i get an error :
Compile error:
For Each may only iterate over a collection object or an array.
does that mean that my array is recognized as so by vb, what is wrong with my code ?
Here is what i've done
I've tried to right a code to simulate the if function by defining an array.
But i get an error :
Compile error:
For Each may only iterate over a collection object or an array.
does that mean that my array is recognized as so by vb, what is wrong with my code ?
Here is what i've done
Code:
'Copy COST FOR NATIONAL CALLS
TotalIN = 0
ActiveWorkbook.Sheets("Section7").Activate
Dim Tata As String, xItem As Variant
LastRow = Cells(Rows.Count, "O").End(xlUp).Row
Tata = Array("Communications nationales", _
"National communications", _
"Supplementary services")
For Each xItem In Tata
National = National + WorksheetFunction.SumIf(Range("O2:O" & LastRow), xItem, Range("R2:R" & LastRow))
Next
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
Dim reduction As String
reduction = InputBox(prompt:="What is the discount percentage ?", _
Title:="Please entre the discount percentage for national calls", Default:="37")
Range("A9").Value = "Net cost (" & reduction & "%)"
cnp = (National * reduction) / 100
Range("C9").Value = National - cnp
Range("C8:C9").Style = "Currency"
'Copy COST FOR INTERNATIONAL CALLS
TotalIN = 0
ActiveWorkbook.Sheets("Section7").Activate
Dim Toto As String, vItem As Variant
LastRow = Cells(Rows.Count, "O").End(xlUp).Row
Toto = Array("Communications internationales", _
"International communications")
For Each vItem In Toto
intNational = intNational + WorksheetFunction.SumIf(Range("O2:O" & LastRow), vItem, Range("R2:R" & LastRow))
Next
ActiveWorkbook.Sheets("SynthesisVSD").Activate
Range("C10:C11").NumberFormat = "0.00"
Range("A10").Value = "Total cost of International Communications"
Range("B10").Value = "Gross cost : "
Range("C10").Value = intNational
Dim reductionint As String
reductionint = InputBox(prompt:="What is the discount percentage ?", _
Title:="Please entre the discount percentage for international calls", Default:="43.5")
Range("A9").Value = "Net cost (" & reduction & "%)"
cnp = (National * reduction) / 100
Range("C9").Value = intNational - cnp
Range("C8:C9").Style = "Currency"