compile error can't assign to array

kiwilife

Board Regular
Joined
Jul 21, 2005
Messages
66
arraytype is an argument in the function. If argument is staffcost i want myarray which is an array i created to contain staffcost values(Range"A93:M192"). If argument is general, i want myarray to store general value Range("A191:M222"). However i have an error saying that compile error cant assign to array.. Thanks for any help..

If arraytype = "staffcost" Then
Dim myarray(32, 13)
checknum = 1
For z = 93 To 129
ck = Cells(z, 1)
If ck <> " Bonus" And ck <> " Salary" And ck <> " Pension Fund" And ck <> " Benefits" And ck <> " Contract Cost" Then
For x = 1 To 13
myarray(checknum, x) = Cells(z, x)
Next x
checknum = checknum + 1
End If
Next z

ElseIf arraytype = "general" Then
myarray = Range("A191:M222")
End If
 
Hi kiwilife

You can only make an assignement to an array if the array has not be dimensioned.

Try:

Code:
Dim myarray As Variant
 
If arraytype = "staffcost" Then

    ReDim myarray(1 To 32, 1 To 13)
    ' ... code

ElseIf arraytype = "general" Then

    myarray = Range("A191:M222")

End If
 
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