Type mismatch error

G

Gautam

When i try the following statement in a macro, i get an error 13, Type
mismatch. Could anyone solve this please
ActiveSheet.Cells(j, colcount) = (data(j, i)) / 587

array data is declared as variant

Thanks
 
P

paul.robinson

Hi
data should be an array e.g.

Dim data(1 to 10, 1 to 10) as double

Sometimes you need to pass arrays as variants (e.g. when trying to
copy an array to a range on a worksheet). Then you would do

Dim Variant_data as Variant
Variant_data = data

and you can access the numbers in Variant_data exactly as if it is an
array. But you MUST create data as an array FIRST and then make your
variant.

regards
Paul
 
J

Joel

the statement was not giving me an error. Tried a couple of ways of ways to
get errror 13. the only way I found of getting error 13 was to declare data
as a string
Dim data(10,10) as string.

Check the declaration of the array data.
 
D

Dave Peterson

Check your other post.
When i try the following statement in a macro, i get an error 13, Type
mismatch. Could anyone solve this please
ActiveSheet.Cells(j, colcount) = (data(j, i)) / 587

array data is declared as variant

Thanks
 
G

Gautam

the statement was not giving me an error. Tried a couple of ways of ways to
get errror 13. the only way I found of getting error 13 was to declare data
as a string
Dim data(10,10) as string.

Check the declaration of the array data.







- Show quoted text -

Thanks Joel
The first part of the array was indeed a string
 
G

Gautam

Hi
data should be an array e.g.

Dim data(1 to 10, 1 to 10) as double

Sometimes you need to pass arrays as variants (e.g. when trying to
copy an array to a range on a worksheet). Then you would do

Dim Variant_data as Variant
Variant_data = data

and you can access the numbers in Variant_data exactly as if it is an
array. But you MUST create data as an array FIRST and then make your
variant.

regards
Paul





- Show quoted text -

Thanks Paul
The first part of the array was a string which popped an error
the other part of the code is fine
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top