Build an array from certain columns on worksheet

JumboCactuar

Well-known Member
Joined
Nov 16, 2016
Messages
785
Office Version
  1. 365
Platform
  1. Windows
Hi,

if i have data in range("A2:Z1000")

what is the best way to build an array from this but only specific columns

e.g 3 columns into an array
D2:D1000, G2:G1000, A2,A1000


thanks
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
You want each row of the array to be in that order, column D, column G and then column A

VBA Code:
Dim i As Long
Dim j as Long
Dim myArray as Variant

With Range("A2:Z100")
   Redim myArray(1 to .Rows.Count, 1 to 3)

    For i = 1 to .Rows.Count
        myArray(i,1) = .Cells(i, 4).Value
        myArray(i, 2) = .Cells(i, 7).Value
        myArray(i, 3) = .Cells(i, 1).Value
    Next i
 
End With
 
Upvote 0
How about
VBA Code:
Sub JumboCactuar()
   Dim Ary As Variant
   
   Ary = Application.Index(Range("A2:G1000").Value, Evaluate("row(1:999)"), Array(4, 7, 1))
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,251
Members
448,556
Latest member
peterhess2002

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