Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assigning range to array in VBA

Tags:

excel

vba

I would like to get excel data into an array in VBA, so I do the following:

Dim Arr() As Variant
Arr = ActiveWorkbook.Sheets("Sheet1").Range("C28:R29")

As soon as I run this, I get a type mismatch error 13. I thought the problem was because the 1st row (2 rows in total) represents a string (header) and the 2nd row represents numbers, so I tried to only get one row like this:

Arr= ActiveWorkbook.Sheets("Sheet1").Range("C28:R28")

To no avail, I still get the same problem.

Does anyone know what could be wrong?

Regards Crouz

like image 885
Crouzilles Avatar asked Sep 14 '26 06:09

Crouzilles


1 Answers

It's pretty simple, just add .Value (I discovered that trick not so long ago and I'm already fan! :) )

Arr= ActiveWorkbook.Sheets("Sheet1").Range("C28:R28").Value2
like image 148
R3uK Avatar answered Sep 16 '26 06:09

R3uK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!