Excel VBA Type

In VBA, you can create your own data types using the Type keyword. It’s very similar to struct data type from other programming languages.

It consists of one or multiple existing types into one new type. A good example of using this data types is a database record. If you want to keep a record of your employees, it’s a good idea to use the Type structure.

Type Employee
first_name As String
last_name As String
id_number As Integer
salary As Long
End Type

A variable declared as Employee will have all these data types built-in. You declare user-defined types the same way as you declare standard built-in VBA types.

Dim emp As Employee

Now, you can access individual fields of this structure by using the dot (.) operator. You can assign a value to any of the Employee types.