VBA Excel – How to convert range to array easily

Converting a range to array makes a lot of sense in VBA, when some operations should be performed with data in a given range. The time saving is quite noticeable and it is a bit easier to access and modify the data there. However, there is one small trick that we need to know, if we are converting one line range to array – if we do it just like this: myArr = Range(“A1:A10”), the new array will be with two dimensions. Which is not always somehow comfortable to work with:

To get away of the two dimensions, when getting a single column to array, we may use the built-in Excel function “Transpose”. With it, the data becomes in one dimension:

If we have the data in a row, a single transpose will not do the job. We need to use the Transpose function twice. It will work then.

In newer versions of Excel, the function is Application.WorksheetFunction.Transpose().

Cheers! 🙂

Tagged with: , , , ,