Yugal Jindle
Yugal Jindle

Reputation: 45666

Exception when trying iterate Excel range.value like array ? (Help Debug)

I tried the following : (VB.Net code)

Dim data As Object
Dim range As Excel.Range
range = WB.Sheets("mysheet").Range("A1:C5")
data = range.Value   ' Here WB is the Wrokbook object
' Until here its working fine.
' During Debug: I can see data with values for [ (0,0), (0,1), (0,2), (1,0), .. ]
' Now following line gives an exception !!
Dim val = data(0,0)  ' Index out of range exception.

How can I iterate the so called RangeValueDataType object like an array ?

Reference: http://msdn.microsoft.com/en-us/library/bb238606(v=office.12).aspx

Upvotes: 0

Views: 284

Answers (1)

pabdulin
pabdulin

Reputation: 35227

AFIAK Excel Range data is array with 1 base index, i.e. first item will be data(1, 1).

Upvotes: 1

Related Questions