Help with array's and ranges

Ragnar1211

Well-known Member
Joined
Jul 10, 2008
Messages
572
I am trying to learn something about using arrays with excel ranges.

The following code works fine, it takes the data in the range and feeds it into an array then it puts that data somewhere else:

Code:
sub array2test()
dim ar1

ar1 = range("a2:b10")

range("L2:M10") = ar1

end sub

However, I cannot figure out how to put a part of the array into a range without looping:

Code:
sub array2test()
dim ar1

ar1 = range("a2:b10")

range("M2:M10") = ar1  '<-- I only want the second column of ar1, but don't know how to get it

end sub

Question - how do you get the second column of an array without looping through it?

[/code]
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Hi Gerry

Try:

Code:
Sub array2test()
Dim ar1
 
ar1 = Range("a2:b10")
 
'v-- I only want the second column of ar1, but don't know how to get it
 
Range("M2:M10") = Application.WorksheetFunction.Index(ar1, 0, 2)
 
End Sub
 
Upvote 0
Are there other ways to do this without using the Index function? Just curious.

I don't know. Vba is very poor as far as this type of array manipulation is concerned. I think you do have to use worksheet functions if you don't want to use a loop.
 
Upvote 0
Use a loop to transfer data from column 2 of the matrix to a new 1D array. Then, transfer that to the worksheet.

In memory transfers are very fast. It's the transfer to worksheet one-cell-at-a-time that is painfully slow.

Thanks!

Are there other ways to do this without using the Index function? Just curious.
 
Upvote 0

Forum statistics

Threads
1,214,397
Messages
6,119,273
Members
448,883
Latest member
fyfe54

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