How to Declare (Dim) and Set VBA Variables (use data types correctly)

preview_player
Показать описание

It’s best practice to declare your Excel VBA variables before you use them. Declaring variables means that you give VBA a heads up that it needs to free up some memory space for your variables which will in most cases be less than the default. That's why it's important to understand the concept of data types and how much memory space each of these types will take. The less memory you allocate to a variable, the faster your code will run. I show the range associated to each data type - such as numbers, text, date, currency etc in the video.

Key Highlights:
- Default Data Type: By default, VBA assigns the data type called "Variant," which adapts based on the data it holds, leading to larger memory consumption.
- Memory Efficiency: Different data types consume varying amounts of memory. For instance, a "Byte" takes up only one byte of memory, while a "Variant" uses around 16 bytes.
- Data Type Ranges: Each data type has a specific range it can handle, which becomes crucial in scenarios where the data exceeds that range.
- Common Data Types: Explore popular data types like "Byte," "Integer," "Long," "Boolean," "Double," "String," and "Object," each with its own purpose and memory footprint.
- Variable Declaration: Learn how to declare variables using the "DIM" keyword, and understand naming conventions for variables.

★ Links to related videos: ★

🚩Let’s connect on social:

Note: This description contains affiliate links, which means at no additional cost to you, we will receive a small commission if you make a purchase using the links. This helps support the channel and allows us to continue to make videos like this. Thank you for your support!

#ExcelVBA
Рекомендации по теме
Комментарии
Автор

This helped explain a bunch for me. Usually videos don't help much when it comes to coding but this was actually very helpful. Thank you!

dschulz
Автор

During such lock down, watching such easy explanation of tough topic is awesome..
U r up to the point and so clear, and same time so

dhruvilbarbhaya
Автор

Another great video! Dim, Set and such have been the bane of my existence, so It's good to have it explained clearly. I'll be watching this a couple more times, just to be sure I really get a grasp on it! (People have tried to explain these to me before, but they get into too much "tech jargon" that makes my brain spin around, LOL!)
Thank you!

jennydrumm
Автор

Thanks for the great Data Type video!!

excelisfun
Автор

Very informative, waiting some more Videos on the VBA, eagerly. Your Explanation is Excellent, and crystal clear.

gopalakrishnarao
Автор

Thank you. Your vba and excel courses are excellent.

tannertucker
Автор

Intriguing rabbit hole I have stumbled upon.

amc
Автор

superb. i like the way you touch every small point while explaining.

Oshokebachan
Автор

Die Übersicht ist extrem hilfreich! ☺️

HoppiHopp
Автор

Your tutorials are very good. thank you.

pedrocamara
Автор

Thank you for the error example. That has been frustrating to work through and your explanation is very helpful.

joshzink
Автор

I have multiple disabilities and health problems. In my sixties now and lost my job because of a love of Excel makes me want to learn vba. I recorded a macro that "Cleared Content" from multiple non contiguous Ranges. I went into gab to run it but kept getting an error at lines of code starting with "Union Range." Can't understand it. Is it simple to rectify? Your channel is IMHO the best on You Tube for Excel. Well explained. Great examples and explanations. Superb. Thank you very much

mdcs
Автор

oh! Just the info I was looking for. Now my macro works! Thanks.

dddoda
Автор

Thank you Leila. You are always amazing!

marcellokassa
Автор

Love your videos, they are clear and easy to understand. :D

tanwen
Автор

Hi Leila, a minor correction:
The largest positive number that the INTEGER data type can hold is not: 32768 but: 32767.
Thank you for your excellent videos 🙂

meniporat
Автор

Useful and clear as always, I love <3 your videos Leila!

felipao
Автор

Very Informative & useful. Thank you for uploading & expecting more.

md.mahbubrahman
Автор

LET used in old BASIC programming language. I remembered it first time i saw Spectrum's Sinclair Basic

Thanogr
Автор

This video is good.in some videos of others I saw no dim is used in the beginning.
Can u define all the codes why it is used for and when with elaboration.

Trendinvideowalasam