macro array help

tuytuy

Board Regular
Joined
Mar 28, 2013
Messages
75
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
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"
 
Dim Tata As String
....
Dim Toto As String

eliminate as string, because they are array
 
Upvote 0
Try

For i = lbound(Toto) to ubound(Toto)

'do something with Toto(i)

next i
 
Upvote 0

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