How to fill or load the data of an Excel sheet range into a vector

In this respect, once again the Visual Basic language stands out, the one that allows this type of configuration and data transfer.

Vector definition based on Visual Basic

Before working with vectors, you must first learn what they are and how they are used. Vectors are commonly known as containing lists two or more numbers which can be aligned in a row or in a column.

In Visual Basic terminology, like arrays, they are called " Array »Or» Array »Which also have different dimensions and whose mathematical operations can be performed according to certain parameters.




These arrays are known as dynamic vectors since the duration of the data is not known, which is why these vectors can be scaled.

How to fill or load the data of an Excel sheet range into a vector

A feature of this type of arrangement is that it allows you to store multiple sets of values, in the form of a list, that belong to the same data type.

Method for loading data from a range to a vector

using Microsoft Excel 2013 there are two ways to load values ​​into the vector. In this first method, the data transfer will be done through a specific interval.

These vectors are declared differently than usual through Visual Basic, because you don't know how much data is in the range that will be used.

Likewise, the dimension or range parameter cannot be defined to be used as an index variable since the program does not allow this style of operations.

The solution to this factor is declare the vector as a fixed range, so that the data can be loaded via the macro code.



Start by going to the page » Developer »To find the button» Editor in Visual Basic »And start a new one" Module »For your project book.


Add the title of the macro you will start encoding with and declare the vector you will use as " Interval «, So that Excel knows it will contain a range of cells.

The variable will have the task of holding the value of the last position of the range, so if you keep adding values ​​to the established field, it will always take the last of these.

For this it is necessary to declare it as " Whole or Whole ", Adding the calculation of the last line of the range with the code of the default variable for vectors known as" NomeVariabilePrecedente = sheets ("Sheet1"). Range ("A" & lines.Count) .end (xlup) .row «.

Now it can load data from a range to a vector via the term " Set »Determining the value of the last line of the field.

How to fill or load the data of an Excel sheet range into a vector

To show a specific value, you just need to write where it is and finish saving the code. When you minimize the editor, a window should appear with the value that has been set in the vector.

Macro code of the process

Public secondary load carrier ()

Dim vector1 As Range

Dim last line as an integer


LastRow = Fogli (“Sheet1”).Range (“A” & Rows.Count).End (xlUp).Row

Set vector1 = Interval ("A1: A" and lastRow)

MagBox1 Vector (5)


End subtitle

The second method differs from the previous one in that instead of setting a range start and a last row, the data in the range is actually set via a hatch selection.



As for the coding, the terms ranging from " Dim lastFila… » a » Set vector1… Would come deleted to read them as follows:

Public secondary load carrier ()


Dim vector1 As Range

Set Vector1 = Range (Select.Address)

MagBox1 Vector (2)

End subtitle

This way in the vector window will come displayed the value found in the second cell that is inside the shading performed during encoding macro.

If you have already loaded data from a range into a vector, you may be interested in loading the vector values ​​into a CombBox object, which makes it easier to read and simplifies the data it has. The ComboBox can be configured to avoid data repetition.


add a comment of How to fill or load the data of an Excel sheet range into a vector
Comment sent successfully! We will review it in the next few hours.