Pass two columns of array to a temp array - syntax

GeeWhiz7

Board Regular
Joined
Nov 22, 2021
Messages
214
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi folks,
I am having trouble figuring out how to copy two separate columns from one array into a separate temporary array. I can't assign just those two columns earlier in the process unfortunately so am trying to figure it out this way.

origArray data example:
5/3/2021​
125.37​
125.57​
124.28​
124.5​
124.5​
619300​
5/4/2021​
123.99​
124.03​
121.67​
123.51​
123.51​
812500​
5/5/2021​
123.96​
124.51​
122.44​
122.61​
122.61​
996900​
5/6/2021​
123.05​
123.05​
120.73​
122.54​
122.54​
676400​
5/7/2021​
122.79​
125.07​
122.49​
124.56​
124.56​
845300​
5/10/2021​
123.98​
125.23​
121.66​
123.11​
123.11​
726500​
5/11/2021​
123.26​
123.6​
120.61​
121.04​
121.04​
851400​
5/12/2021​
118.83​
120.13​
117.6​
118.1​
118.1​
1187700​
5/13/2021​
119.28​
121.11​
119​
120.49​
120.49​
916500​

I would like to pass only the entire columns 1 (dates) and 6 (adjusted close) to a temporary array (varTemp)
I know how to do single rows using INDEX with the following snippet, but I don't know how to do entire columns and more than one. Right now I just bring it all in and then run a macro to copy columns 1 and 6, but I was hoping to find a cleaner way.

VBA Code:
'Print Row 3 to see it
    varTemp = Application.WorksheetFunction.Index(origArray, 3, 0)
    Debug.Print Join(varTemp, ",")
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
You can use this to create a 2d array with just the two columns
VBA Code:
   Dim origArray As Variant, varTemp As Variant
   origArray = Range("A2:G10").Value2
   varTemp = Application.Index(origArray, Evaluate("row(1:" & UBound(origArray) & ")"), Array(1, 6))
 
Upvote 0
Solution
You can use this to create a 2d array with just the two columns
VBA Code:
   Dim origArray As Variant, varTemp As Variant
   origArray = Range("A2:G10").Value2
   varTemp = Application.Index(origArray, Evaluate("row(1:" & UBound(origArray) & ")"), Array(1, 6))
Fluff, this works perfectly, thank you for sharing it with me. I did not even know of Evaluate before...can't say I even know what it means looking at your code so will look it up. Thanks!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,823
Messages
6,121,777
Members
449,049
Latest member
greyangel23

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