If you are working with several variables that relate to one thing, for example you are working with employee data, and every employee has a first name, last name, location and salary, you could set them up like this
But if you want to work with data relating to several employees then you're going to end up creating a whole bunch of variables and it could get messy.
In a situation like this you might be better off to create a custom data type. A custom data type allows you to gather several variables about one thing into its own type.
You can think of the custom data type as a box into which you place all the data relating to one thing.
To set up a data type for our employees we first create a new code module and then define the type
To use this new type we can use a DIM statement like any other data type.
With the Employee type declared at the top of your module, it will now appear in Intellisense
To access the variables inside the new emp
Again, you can see that Intellisense knows that emp contains four variables and shows them in the drop down as I'm typing.
Your custom type can contain variables that are basic VBA data types, other custom types, classes or objects.