caselton

New Member
Joined
Apr 21, 2018
Messages
13
Hi Everyone
I have a problem which is driving me crazy

the code below is just a simple example of my issues

Code:
Dim blah(1 To 6) As Variant


For q = 1 To 6
MsgBox q
d = q * 2
blah(q) = d
MsgBox d
Next q


Range("x1:x6") = blah

why does the array not populate blah(q) with the new value for d each loop
the output is all one value and in this case it was all 2's

Any help greatly appreciated
 
Last edited:

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
When using this formulation

Range("x1:x6") = blah

to write to the worksheet, it must be a 2-dimensional array, even if one dimension is 1. Try this:

Rich (BB code):
Dim blah(1 To 6, 1 To 1) As Variant




For q = 1 To 6
MsgBox q
d = q * 2
blah(q, 1) = d
MsgBox d
Next q




Range("x1:x6") = blah
 
Upvote 0
When using this formulation

Range("x1:x6") = blah

to write to the worksheet, it must be a 2-dimensional array, even if one dimension is 1. Try this:

Rich (BB code):
Dim blah(1 To 6, 1 To 1) As Variant




For q = 1 To 6
MsgBox q
d = q * 2
blah(q, 1) = d
MsgBox d
Next q




Range("x1:x6") = blah




Legend, many thanks
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,028
Messages
6,128,399
Members
449,447
Latest member
M V Arun

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