Copy a Range of Excel to an Array using VB.net

ubifsj

New Member
Joined
Jun 19, 2016
Messages
4
Hello

I'm trying to copy a range of cells from an excelsheet to an array in Vb.net. But the last line doesn't seem to be working! Any idea how I can fix the problem?

Imports MyExcel = Microsoft.Office.Interop.Excel
Dim MyArray (3) As String

MyArray = MyWorksheet.Range("D2", "D4").Value


I can make it work for with a For Loop but not using the range.value

Thanks
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
It Doesn't work. Variant is no longer supported. Instead Object to be used. Also Range(("D2").value) could be a string so it's not the solution!
 
Upvote 0
No it's not an excel issue. It's not supported in newer version of VB.net using Visual Studio. The message says: Variant is not a supported version, Use the Object Type instead.
I found the solution. I had to declare the MyArray as a two dimensional array.
Private MyArray(,) As Object = Nothing
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

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