Excel

TheSmallman.com

an XL ideas Lab

Dashboards VBA
  • Home
  • Dashboards
    • Tips & Tricks
    • Charts
    • Modelling
    • Infographics
    • VBA
  • Shop Dashboards
    • Power Pivot a User Guide
    • Excel Dashboard Course
    • Advanced Dashboard Course
    • Financial Modelling Course
    • Excel VBA Course
  • Blog
  • About
Menu

Excel Dashboards VBA

Street Address
City, State, Zip
Phone Number
an XL ideas Lab

Your Custom Text Here

Excel Dashboards VBA

  • Home
  • Dashboards
  • Excel Tips
    • Tips & Tricks
    • Charts
    • Modelling
    • Infographics
    • VBA
  • Shop Dashboards
  • PowerPivot
    • Power Pivot a User Guide
  • Courses
    • Excel Dashboard Course
    • Advanced Dashboard Course
    • Financial Modelling Course
    • Excel VBA Course
  • Blog
  • About

Read Individual Columns to an Array

April 12, 2016 Marcus Small
Photo by Phil Goodwin on Unsplash

Photo by Phil Goodwin on Unsplash

In Excel VBA as I have shown previously you can push data between 2 or more arrays.  There have been a glut of examples on this website where I have moved data from one array to another.  There have even been examples where I have moved only certain columns into a single array.  The following method with you the INDEX formula within VBA to move data from one array to another but only move the columns which are specified.  With the following method of the 6 column array (Cols A – F) only columns A, C and E will be moved from the first variant, to the second variant.  The code looks a little as follows.

Sub ReadCertainColstoArray() 'Read only Cols 1,3,5 into an Array.
Dim ar as Variant
Dim var as Variant

ar = [A1:F15]
var = Application.Index(ar, [row(1:15)], Array(1, 3, 5))
   Range("J1:L" & UBound(var)) = var 'Output the Array.
End Sub

The variant (ar) holds the initial data and the variant(var) accepts only columns 1, 3, 5 as stated in the Index line. 

var = Application.Index(ar, [row(1:15)], Array(1, 3, 5))

So the index is doing all the heavy lifting so the only data flowing through is the ones specified (1,3,5).

The final part of the equation is to output the variant (var).  This is done with the following line. 

Range("J1:L" & UBound(var)) = var

It is based on the size of the variable (var).  The upper bound of the Variable (15 rows) will be the cells which are filled.   The following Excel file outlines the procedure with some data.

FillSpecific.xls

Tags VBA, Excel, Copy, columns, array
← Excel Change Print Area with VBA Excel Import Data from Multiple Cells →

Featured Posts

Excel Dashboards: Tracking a Crisis

Excel Dashboards: Tracking a Crisis
April 14, 2020

Recent Posts

Populating an Excel Table from a Range of Cells with VBA

Populating an Excel Table from a Range of Cells with VBA June 12, 2025

Fuzzy Distribution with Randbetween

Fuzzy Distribution with Randbetween May 21, 2025

Add Minimum and Maximum for Chart in Cells

Add Minimum and Maximum for Chart in Cells March 12, 2025

Inflation Over Multiple Years in a Single Cell

Inflation Over Multiple Years in a Single Cell January 10, 2025

Hubspot Dashboard

Hubspot Dashboard October 3, 2024

Monthly Dashboard With Supporting Metrics

Monthly Dashboard With Supporting Metrics September 25, 2024

Excel Show Missing Sheet Tabs

Excel Show Missing Sheet Tabs July 29, 2024

Run Macro Overnight Automatically

Run Macro Overnight Automatically June 24, 2024

Split File into Parts and Save to Directory

Split File into Parts and Save to Directory April 20, 2024

Most Popular Author

Most Popular Author December 14, 2023

 

Follow US:

 
 

MarcusSmall@thesmallman.com

 

TheSmallman.com - Making your small systems hum...
© Copyright 2013-2024 theSmallman.com All Rights Reserved.