VBA: questions about working with arrays

BIGTONE559

Active Member
Joined
Apr 20, 2011
Messages
336
Greetings,

I'm trying to learn how to work with arrays. in this sample that i wrote i keep receiving an error at the "Msgbox MyArray(i)" line. the goal is to have the msgbox cycle through all of the values in the array. the error is "Subscript out of Range"

Code:
Sub Sample()
Dim i As Integer


Dim MyArray() As Variant
MyArray = Range("MyDates")
For i = 1 To UBound(MyArray)
MsgBox MyArray(i)
Next i

End Sub
All help is appreciated.
 
ok i've reached another stumbling block. upon trying to have a value entered into a cell i receive an application or object defined error.

e.g.

Code:
Worksheets("Test").Range(Cells(1, 2)).Value = myarray(1, 1)

if i write the line:

Code:
msgbox MyArray(1,1)
i receive the msgbox with 05/21/2012 however i cannot get this value in a cell????


WHY NOT?????
 
Upvote 0

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
ok i've reached another stumbling block. upon trying to have a value entered into a cell i receive an application or object defined error.

e.g.

Code:
Worksheets("Test").Range(Cells(1, 2)).Value = myarray(1, 1)
if i write the line:

Code:
msgbox MyArray(1,1)
i receive the msgbox with 05/21/2012 however i cannot get this value in a cell????


WHY NOT?????

i am sooooooooooooooooo dumb!!!!!!!!!!!!! i noticed that i wasn't defining the range properly. . .

. . .
 
Upvote 0

Forum statistics

Threads
1,216,216
Messages
6,129,564
Members
449,516
Latest member
lukaderanged

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