Return to VBA Code Examples

VBA Output (Print) Array to Range

This tutorial will demonstrate how to output an array to a range using VBA.

Output (Print) Array to Range

Data that is stored in an array can easily be outputted into an Excel sheet.  There are 3 ways to do this.

Output Data to a Different Range

We could populate an array with data from one range in Excel, and then output the data to a different range in Excel.

The entire array is copied in one line of code to the array, and then outputted in it’s entirety to a different range of cells on the sheet.

Looping Through an Array and Outputting the data

This example will loop through an array, outputting the array to a range.

LBound and UBound returns the Starting index (Lower Bound) and Ending index (Upper Bound) of an array, in this case 1 and 10.

Transpose Array Data

We can also transpose the data in the Array to the Excel sheet.  Transpose allows you to display the data horizontally across the Excel sheet.

For example, if we have a list of states in Excel and wish to transpose them.

vba array transpose 1

We could then run the following code:

Which would result in the following:

vba array transpose 2

Output to Debug.Print

We can also output the array values to the debug window.

 

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users! vba save as


Learn More!