Array problems

richarddawson

Board Regular
Joined
Oct 18, 2014
Messages
87
I have a single sheet workbook; with A1 = "a"; A2 = "b"; down to A6 = "f".

The entire programme is below
The bounds print correctly ; 1 6
But I get an error '9' "Subscript out of range" on the next line ("Debug.Print Arr(3)")

I have used arrays many times - but this defeats me - can anyone help, please?

Dim Arr() As Variant
Sub getArray()
Arr = Range("A1:A6")
Debug.Print LBound(Arr) & " " & UBound(Arr)
Debug.Print Arr(3)
End Sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
As Arr is a 2d array, you need to use
VBA Code:
Debug.Print Arr(3,1)
 
Upvote 0
Solution
Thanks for your rapid and succinct answer - which certainly eliminates the "Subscript out of range" problem, but it
does not print anything.

Also I thought I had only specified a one dimensional array!

Cheers Rochard
 
Upvote 0
Whenever you load a range into an array, it will always be a 2d array.
If it does not print anything check that A3 on the active sheet is not blank.
 
Upvote 0

Forum statistics

Threads
1,214,956
Messages
6,122,465
Members
449,085
Latest member
ExcelError

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