Question

In a function I define my array like below but the function gives me #value when I use it in the worksheet. It works when I leave the part Worksheets("interestrates")., however, in the wrong sheet then. What can I do, to tell Excel to fill the array with values from the worksheet "interestrates"

array1 = Worksheets("interestrates").Range("a" & range1.Value & ":c" & range2.Value)

Was it helpful?

Solution

Assuming range1 and range2 are single cell Range objects which evaluate to an integer/long value, I believe this is your problem:

You have a multi-dimensional array (3 columns, and a varying number of rows to be determined by the maximum of range1 or range2). The number of rows doesn't really matter. The problem is that you cannot put an array of values in a single cell.

Long story short, you should certainly be able to assign to an array like you are doing, for example:

enter image description here

If your function is returning #Value! error, then there is some problem with the rest of your function, or with what you are expecting/attempting to do with the function.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top