Search code examples
arraysvbarangeexcel-indirect

Load range to array depending on row numbers specified in sheet


Does anyone know how I can substitute the following code with a dynamic one that is linked to specific cells?

i.e. replace this

dim array1()
array1=range("a150:k250")

with something similar to that

dim array1()
array1=range(application.indirect("a"&c1&":k"&d1)

where c1 contains the value 150 and d1 the value 250


Solution

  • Drop the indirect, use the Value property on C1 and D1 instead:

    array1=Range("a" & Range("c1").Value & ":k" & Range("d1").Value)