Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Text to Columns

The Range.TextToColumns method in VBA is a powerful tool for cleaning up data that has been
imported from text or csv files

Text To Column option in excel is available in the Data menu tab under the Data Tools section, which is
used for separated text available in a cell or column to the columns by splitting them with different
criteria. Mostly this process is called the delimiting process, where we split or separate the text into the
column with spaces, commas, any word, or else we can use a fixed-width option by which text will be
placed into cells of the same row from the point we want to break it.

1. Delimited: This feature splits the text, which is being joined by characters, Commas, Tabs, Spaces,
Semicolon or any other character such as a hyphen (-).

2. Fixed Width: This feature splits the text which is being joined with spaces with some certain width.

INTERIOR COLLECTION
Collections are a very important part of VBA. If you have used the language for any length of time then
you will have used Collections. The most common ones are the Workbooks, Worksheets, Range and
Cells collections The main difference is that with an array you normally set the size once. This means
that you know the size before you start adding elements. Let me explain this with an example.

Changing background colors in Excel VBA is easy. Use the Interior property to return an Interior object.
Then use the ColorIndex property of the Interior object to set the background color of a cell.

The class Interior represents the interior of an object. The classes AboveAverage, CellFormat,
DisplayFormat, FormatCondition, OLEObject, Range, Style, TableStyleElement, Top10 and UniqueValues.
give access to class Interior

To use a Interior class variable it first needs to be instantiated, for example

Dim int as Interior

Set int = ActiveCell.Interior

The following procedures can be used to set variables of type Interior: AboveAverage.Interior,
CellFormat.Interior, DisplayFormat.Interior, FormatCondition.Interior, OLEObject.Interior,
OLEObjects.Interior, Range.Interior, Style.Interior, TableStyleElement.Interior, Top10.Interior and
UniqueValues.Interior.
PROPERTIES
Color returns or sets the primary color of the object, as shown in the table in the remarks section. Use
the RGB function to create a color value.

ColorIndex returns or sets a value that represents the color of the interior.

Gradient returns or sets the Gradient property of an Interior object of a selection.

InvertIfNegative true if Microsoft Excel inverts the pattern in the item when it corresponds to a negative
number.

Pattern returns or sets a Variant value, containing an XlPattern constant, that represents the interior
pattern.

PatternColor returns or sets the color of the interior pattern as an RGB value.

PatternColorIndex returns or sets the color of the interior pattern as an index into the current color
palette, or as one of the following XlColorIndex constants: xlColorIndexAutomatic or xlColorIndexNone.
Read/write Long.

PatternThemeColor returns or sets a theme color pattern for an Interior object.

PatternTintAndShade returns or sets a tint and shade pattern for an Interior object.

ThemeColor returns or sets a Variant value, containing an XlThemeColor constant, that represents the
color. Read/write Variant.

TintAndShade returns or sets a Single that lightens or darkens a color.


Sort Method in Excel VBA
The front-end dialog box is found by clicking the ‘Sort’ icon in the ‘Sort & Filter’ group of the ‘Data’
tab on the Excel ribbon. You need to select a range of tabular data first.

VBA has a Range.Sort method to sort the data for you. Where Range specifies
the range of cells which we want to sort out in ascending or descending order.

With the sort method, you need to provide some additional information
through parameters. Below are the key parameters you need to know:

 Key – here you need to specify the column that you want to sort. For
example, if you want to sort column A, you need to use
key:=Range(“A1”)
 Order – here you specify whether you want the sorting in an ascending
order or the descending order. For example, if you want the sorting in
ascending order, you will use Order:=xlAscending
 Header – here you specify whether your data set has headers or not. If
it has headers, the sorting starts from the second row of the data set,
else it starts from the first row. To specify that your data has headers,
you will use Header:=xlYes

Excel VBA Intersect


The Intersect method in Excel VBA returns a Range object that represents
the intersection of two or more ranges

VBA Intersect  is used to get a range object that is an intersection of


two or more range. The minimum of two ranges should be supplied to
find the intersecting range point. All the other arguments are optional
based on the requirement.

Below is the syntax of the VBA INTERSECT formula.


 Arg1 as Range: First intersecting range.
 Arg2 as Range: Second intersecting range.

Go to the VBA window and open a Module from the Insert menu option 

Now write Subcategory of VBA Intersect or in any other name as per your
choice.

Sub VBAIntersect1()

End Sub

Now directly insert Intersect command

we will add an area of intersection. We can choose N number of ranges but a


minimum of two Ranges should be there.

Dynamic Array
A dynamic array is something where you can resize the array and add more
value to it while running the code. In this tutorial, we will explore the ways to
write a code where you can do both things resizing and adding more
elements.

If the size of your array increases and you don't want to fix the size of the
array, you can use the ReDim keyword. Excel VBA then changes the size of the
array automatically.
Create a Dynamic Array in VBA

First, declare an array with its name.

After that, the elements count left the parentheses empty.

Now, use the ReDim statement.

In the end, specify the count of elements you want to add to the array.
Dim myArray() As String
ReDim myArray(5)

You might also like