Having an array receive its own value

Isoka

New Member
Joined
Mar 16, 2017
Messages
7
Hello,

I am trying to have an array receive its own value plus a specific cell value:
myarray(1) = myarray(1) + Cells(2,4)
But I get error "13": Incompatible types (translated from Portuguese)
I have verified that if I make it:
myarray(1) = Cells(2,4)
It works.
The array has been declared as string.
Please help me out figuring out how to do this. Best regards,
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
If you are working with strings, use the & operator

Code:
myArray(1) = myArray(1) & Cells(2,4).Text
 
Upvote 0
Hi mikerickson, that was quick, thanks! Actually I am working with numbers, up to 100,000. I want to add some value to the array value each time it passes through a loop.
 
Upvote 0
Hello,

I have learned that the array must be declared as Long in order to work with numbers. SOlved!
Thanks.
Best regards,
 
Upvote 0
If they are decimal numbers (e.g. 12.5 instead of 12) the array should be declared Double. Long is a data type for integers only.

Long won't crash the code, but it will remove the fractional part of the numbers.
 
Last edited:
Upvote 0
Thanks mikerickson! I just might change it to Double then.
Problem solved!
Best regards,
 
Upvote 0

Forum statistics

Threads
1,215,633
Messages
6,125,929
Members
449,274
Latest member
mrcsbenson

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