How to add specified columns from one array into another

JONABRA

New Member
Joined
Mar 15, 2019
Messages
19
Hi I have an array mulitple columns wide and I would like to take only a select few columns of that array and add it into another array for use elsewhere. I came across a piece of code that looks like this :

VBA Code:
temparr = Application.Index(mainarray, 0, Array(1, 2, 3, 5, 6, 7))

temparr is ideally just a few selected columns of mainarry, and mainarray is the "master" array with multiple columns of data.

I believe its called splicing, however I can't seem to get it to work, when I check the watches window I notice that only the first row is taken (or whatever row number I put in the place of "0"), I've tried all sorts of combinations of that line of code but I can't seem to get at placing entire columns into "temparr".

I've tried transpose and it does not work either:
VBA Code:
temparr = Application.Index(mainarray, 0, WorksheetFunction.Transpose(Array(1, 2, 3, 5, 6, 7)))

any ideas?

thanks
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Try this way
VBA Code:
temparr = Application.Index(mainarray, Evaluate("row(1:" & UBound(mainarray, 1) & ")"), Array(1, 2, 3, 5, 6, 7))
 
Upvote 0
Solution
Works excellently!

I was fiddling with the evaluate for a little but gave up, wasn't sure it would work with an array.

Thanks Peter_SSs, problem solved!
 
Upvote 0

Forum statistics

Threads
1,215,028
Messages
6,122,749
Members
449,094
Latest member
dsharae57

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