Assign Arr() to Worksheet Range

jim may

Well-known Member
Joined
Jul 4, 2004
Messages
7,484
Note Code below - Code line Marked (in Red) produces my Arr(1) 6 times,
1, 1, 1, 1, 1, 1

Versus my values Arr(1) thru Arr(6) of

1, 2, 3, 4, 5, 6

Trying to solve array mystery, right now..

Thanks,

Jim

Rich (BB code):
Option Base 1

Sub GetNonZeroCells()
Dim Arr()
Dim C As Range
Dim Rng As Range
Dim i As Integer
i = 1
Set Rng = Range("H10:H20")
With Rng
For Each C In Rng
    If C <> 0 Then
        ReDim Preserve Arr(i)
        Arr(i) = C.Value
        i = i + 1
    End If
Next C
End With
i = i - 1
ActiveSheet.Range("J10:J" & i + Range("J10").Row() - 1) = Arr   'SEE HERE !!
End Sub
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Hi Jim.

You need to transpose the array

Code:
ActiveSheet.Range("J10:J" & i + Range("J10").Row() - 1) = Application.Transpose(Arr)
 

jim may

Well-known Member
Joined
Jul 4, 2004
Messages
7,484
VoG, As always thanks -- Is there an brief underlying reason for the "Transpose"?
Jim
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Counter-intuitive I know but think of a one-dimensional array as being horizontal. You need to transpose it to vertical in order to write it to a column.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,593
Messages
5,637,294
Members
416,963
Latest member
zazama

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
Top