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 calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
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,216,116
Messages
6,128,933
Members
449,480
Latest member
yesitisasport

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