Assign Arr() to Worksheet Range

jim may

Well-known Member
Joined
Jul 4, 2004
Messages
7,486
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

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Hi Jim.

You need to transpose the array

Code:
ActiveSheet.Range("J10:J" & i + Range("J10").Row() - 1) = Application.Transpose(Arr)
 
Upvote 0
VoG, As always thanks -- Is there an brief underlying reason for the "Transpose"?
Jim
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,422
Messages
6,119,395
Members
448,891
Latest member
tpierce

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