Hello and welcome back to another class, of course.
But the complete introduction to VBA with Microsoft Excel.
So in this class, what we are going to do is pretty simple.
We are going to talk about the VBA code a little bit more in depth and you'll see it's not that complicated
to understand.
So in the past few classes, what we saw is the micro creation and we talked about the visual basic
studio main page and what it looks like and basically how it works and all those things.
So in this class, what we're going to do, we are going to look at the code behind the micro and we
are even going to modify this code a little bit and play with it to be able to create our own macros.
So you'll see it's going to be pretty cool.
So let's start.
All right.
So first thing they'll ask you to do is pretty simple.
Just write down, for example, somewhere.
So.
Here, let's say, I want to write down, for example, the next thing that I want to do is simply putting
it into a lot of cases.
So here we go.
I have my example pretty much everywhere.
And what I want to do right now is pretty simple.
Let's say I want to take all those cases and reduce their sizes well, not reduce make it a little bit
bigger.
So from 14, I'll go to, let's say, 16.
So how exactly do this?
So pretty simple.
First thing that I want to do is go into my developer type.
Then I'll record my macro and let's call it text size.
So here we go.
So I have my Mac right there.
And what I want to do is select my cells that I will use, then simply increase their size and I can
even make it make a boom, for example.
So make it good as well.
And then that's it.
So I stopped recording my microphone.
So basically, as I explained, all this is converted by Excel into a code.
So this is why it's pretty cool using macros, because all everything that you do is converted into
a code and you will see what it looks like.
So basically, first thing is to be able to have this, you need to click on Visual Baeza.
So what happened?
Is that what you will see in modules?
So basically, if we go there inside of our modules, this code right here have been created and that
basically this code is pretty simple.
It explains what exactly happened and how exactly the macro will work.
But the problem with this code is that there is a little bit too much things inside of it for nothing.
So basically things that we don't necessarily need.
So pretty simple.
Let's talk about this code and try to understand it a little bit more.
So if you look at your code, first thing that you can see is subtext.
So here will be the name of your micro.
So your code starts with sub and ends with and some pretty simple.
And as I said, it's the name of the macro.
So we have text size.
So if you want to modify the name of the macro and modify it right there automatically.
Then hear what we can find is comments for those of you who have a basic prior programming programming
experience, you know, pretty much comments.
Why are they things so common in programming, VBA, Python or any other programming language are there
to give you a hint on why your code is there.
So basically, in this case, we can say that that's Imakura that is used to, I don't know, to make
the text a little bit bigger.
And what's cool about comments is that they are not taking consideration when you guys are running your
show.
Basically, the comments are just there to describe your.
So how to write down the comments?
Pretty simple.
You need to start with this little apostrophe right there.
And what you can do is simply write a description about what we just did.
So basically we can say it's
well, let's make it simple, simpler, so.
Text production, that's it.
So here we go, we have our comment that have been created.
So basically it's just that text reduction.
My crew for my crew, for tax reduction.
All right, so here we go, we have our crew for tax reduction right there.
And basically this is what it does.
Basically, this is what does this matter?
Next year we have our basically macro.
So you can see first thing that you guys can see is the range.
So the range in this case, what it is, is what are the cells that will be affected by the macro.
So basically it starts from the cell G five, which is there, and finishes at the cell 18, which is
right here.
So if we look at it G five to 18.
So basically this is the range of our macro.
All right.
Next thing will be this part of the code.
So basically, this is our micro.
And what you can see, first of all, will be the policy.
So in this case, the palace name is Caliburn.
So we have it right there.
So if you want to change something in your macro and change it automatically here and then the tax size
will be sixteen in this case.
So how exactly we can write down this goal.
You can write down what you can delete the with and with it.
You can write down a selection that fund that, for example, name and change decollete or dot size
and change the size of the size of your tax.
But instead of in this case, writing down each time selection, that font and the thing that you want
to modify, you can write it with a with a with selection that font and write down all the attributes
that you want to work with and in this case, add them or delete them.
So in the case of our example, we only need Calibra Insights and all the rest have been has been generated
by Excel in the case that we are going to use it.
So, for example, strike through superscripts, subscript, outline, phones, shadow and all the other
things.
We are not necessarily using them, so we don't need them.
So what we can do is pretty simple.
We can delete all those right now and we will have and with.
So basically our code would work properly even if we only have this part of the code so we can try to
run it once again.
So what we'll do exactly is pretty simple.
We're just going to go back to delete the bold and the make make the text at 14.
So what we'll do after that, we're going to run our macros.
So how exactly we run our macros simply by clicking right there on the run.
So you can see everything has been changed.
All right, let's part of the code selection that fundable, but it's pretty much the same thing as
right there.
It's just written well in a complete sentence.
So the same way that here.
So if I, for example, write down falls right there, so false.
What's going to happen is when I run my micro.
We go just run it there, as you can see, the both part have has been deleted so you can modify my
macro as I want right here.
All right.
So now that you understand the basics, let's create a really basic module.
What module?
Really basic macro based on this part of the code.
So something that is pretty simple.
So first thing that I'll ask you guys to do will be insert and insert eight module.
So then what we'll do, we are going to create a macro that is based on this one right here.
So we'll just copy all the code that we have here and we are going to modify it.
So then we are going to come back in our module number two in there.
So first thing that we want to change will be the title.
So we'll call it text size part to.
Let's just call it Texas to it's going to be simpler.
So here we are coming to exercise, too.
All right.
So first thing we want to do is change the range.
So in this case, what I want to do with this macro is instead of having this range, I want to have
another range.
So in this case, what range I want to use is pretty it's pretty simple.
I want to use this range right there.
But the problem is.
Well, it's all well, it's right now it works on all this range right here.
So if I run it, as you can see, works on Auldridge.
So first thing that I want to do is simply modify the range to what I want as a range.
I want only this, so I want it from age six to G 17.
So this is exactly what I will do.
I will change the range to age six to G
17.
All right.
So we have everything that we need.
So we have a range that is really so next thing that we want to change will be the type of poly.
So in this case, we want we don't want to have calibrator.
We want to have Ahran.
Let's say we want to have aerial so you can choose any policy that you guys want.
Some will say Irial instead of Calibra, we were going to write down Aryal.
And for the size instead of 16, we want to have 14.
Well, no, let's say 20, 20, 30.
And finally here, so for the selection board, we want to have it in bold.
So we'll write down.
True.
But not only want to have the bold part, we also want to have the italic part right there.
So what we'll do is simply write down pretty much the same thing.
So selection that font and what we want to add will be italic.
So in this case, it telic we want Urtext to be in italic as well.
So we have and there we want it to be true.
All right, so we have everything that we need.
Next thing is pretty simple, it's just testing out our map so we can run it and we can see everything
works fine.
So basically, our Maku is what we have are my crew right there that is only for this part and from
our other my crew that is here.
It's going to be applied on all the text right there, which is pretty cool, and if we want to get
rid of the italic part, we can add.
Well, we can go our model number two.
Take our selection, that font, that italic, and instead of having it as true, we will write it down
false here.
So what it will do, it will also delete the italic part.
So if we run it, as you can see, it's not italic anymore.
And if we are module number two.
Well, as you can see, it works perfectly fine, and right now what we have just did, we have created
a macro that is based on our past macro that is right there.
So pretty simple right now.
Well, let's let's recapitulate everything to be sure that you guys understand how it works.
So first part of our code, pretty simple.
You need to have your name.
So you start your code with writing down.
So then the name of your macros in this in this case, it's text size and that's it.
That's the name of your macro.
Then here you have comments, but those comments are not mandatory.
You can delete them if you want.
We can add them whenever you want in the text.
Well, in your code, it doesn't matter.
Then next thing, the range of where exactly your macros will what your macro will be effective.
So in this case, it's effective from five to 18.
And then you write down your macros once again.
This is just for our basic example.
So here I'm writing down my macros for selection, that font.
I want to modify the type of policy.
So in this case, it's Dutney.
I want to modify the size of my text.
So it's going to be that size.
I want to change it to be bold as well.
So in this case, I want it to be bold.
So here I have I should write down the two.
If I want it to be more and italic, I should write down to write this.
So basically, that's our first model.
So it's for text size, also less thing.
So basically, as I explained at the beginning, the way it's going to be written.
So here I have with selection that font and instead of writing down selection that from that name.
So the same way that it's written right there, I just write down a selection, that font here I can
write down that name, that size and all the other attributes that I want to give to my macro instead
of writing down selection that font each and every time.
So it's a little bit more simpler.
And this is why we're using that with right here.
So we have with and with.
So I hope you guys right now understand a little bit more.
So you can see it's not that complicated and it's pretty simple to understand.
But once again, that's just the basics.
So right now you can practice by yourself, by creating little small world, by by creating small macros
that do some basic stuff like this one.
So that's a first class goes into our next class.