Hello and welcome back to another class of, of course, about the complete introduction to VBA with
Microsoft Excel.
So in the past few classes, we talked about plenty of things.
For example, in the past class, we talked about how to move and, well, how to basically move on,
excel and work with ranges and all this kind of stuff.
And we basically talked about a lot of things that you guys can do with VBA.
So what I want to cover today that we didn't cover as well, and I think it's pretty important to cover.
It's basically the use of colors for you.
Well, for the purpose of creating your applications or your macros.
So it's say you guys want to add some colors to your macro or to yourself how exactly you can do this
and basically what type of code you will need to write down.
So, yes, we can, of course, use macros, but for the purpose of this course, we are going to write
it in the form of a code.
So what I propose you guys to do is pretty simple.
I want to practice what I want to practice also what we have learned.
So basically we are going to create a basic, absolute function and what an absolute Maku that will
work on a cell.
And then we're going to create a macro that is relatively, well, relevant reference, relative reference,
and basically it will be applied everywhere.
And also what I want to add I want to add some basic things, such as a bold italic and all the stuff
like we always do, because I want to use the with the element in this in discourse.
So you'll see we're going to divide our code in to put it in two parts.
All right.
So let's start.
So let's always first thing that you guys will need to do is simply open up your visual basics.
And as always, you go insert and create yourself a module for this macro.
So as always, when it's all done you guys want to do right now is create your procedure.
So it's pretty important to create our procedure because if we don't have one, we will not be able
to work well to create our market.
So let's call let's call it color, because we're going to create colors.
All right.
Amazing.
Right now, what we are going to do is what what we're going to do is pretty simple.
I want to take just a cell.
So basically take a simple cell.
And in this cell, I want to add color.
So basically, I want to make the whole cell colorful.
So like this, for example, or and I want to make the text inside of myself colorful as well.
So here in this case, it's yellow and red and that's what we're going to do in this class.
We're going to talk about what basically how you can do this.
But not only this, we're going to talk about two ways that you guys can write down what you guys can
write colors in Microsoft Excel with the use of VBA, because there is more than one way, because there
is a lot of different colors.
So a pretty simple first thing that we want to do is basically select the range in which we want to
work.
So in this case, we want to work.
Let's say we want to work on the range that is here.
So desex.
Well, it's he said, well, let's say desex.
So write down range and arrange will be the six.
And what to do exactly with this range.
We want to select it at first, so we will select this range at first.
So when it's all done, what do we want to write down something inside of this range?
So we're going to use the selection function and we're going to integrate in the Formula or one C1.
So in this case, it's possible to write it down in two ways because I want to add some color inside
of it, inside of it, so we can write down a selection, then use the width, too.
So basically with and with to not write down, not rewrite selection two times, but in this case we
will write it down this way.
So we rewrite it down to two times the in the second part we are going to use the with two.
So pretty simple.
What we what we need to do at first we to select our what we need to select the formula that we are
going to work with.
And this is going to be our once you want the formula that is used to add text or functions inside of
our cell.
So until now, you guys should know it.
But if you don't, it's not a big deal.
You can check out the first few classes.
So Formula R one, see what and what exactly we want to do.
We want to add a test, so we'll write down test.
All right.
So when it's all done, it's time to add some colors to our test.
Well, to our our cell right there.
So basically, you can write well, you can add two types of color.
You can color the whole cell.
And for this in this case, you will use the function interior.
So interior color or you can simply color the text that is inside of the cell.
So in this case, you simply use that font and color.
Then not only this, there is more than one way that you guys can write down colors on Microsoft Excel
with the use of GIBI.
You can write it down as the code of color.
So basically, by using the code of color or simply by calling your colors, let's say you want to call
the blue, you will write down Vehbi blue.
Once again, that's another example.
So let's try it out, so the first thing that we'll do will simply use the code of color for our first
example.
So in this case, we will write down selection.
That interior, because we are going to work with interior that color.
And in this case, then you simply write down equal and you want to write down the code of your color.
So I want to write down your random number.
So basically, I don't know what I can write.
Here we go.
So you can write down a random number.
I suggested write down big numbers like this one somewhere in number that is in the millions because
this is where the colors are.
So if we run our well, just the first part of our code, as you can see, this is the color that we
get.
So basically.
It's red, so Texas red just put it black.
So here we go.
This is the color that we get to the.
If want to change our color, we can do it to just change the numbers we can instead of can write down
something else and rerun it.
And as you can see, the color will change.
So how exactly you can know the code of your color?
Well, it's pretty simple.
What I suggest you guys to do is simply go on Google and write it down and find out all the different
types of colors or it's going to be somewhere right there.
So basically here you have all the different types of colors that are possible.
Which is once again pretty cool.
So those are all the colors that exists.
All right, so this is what we have done until now.
So what is the next step?
So the next step for all this is pretty simple.
We want to change the color of our text.
So how exactly we will do this?
So pretty simple.
In this case, the function will be a little bit more different.
So we are going to write down what instead of writing the interior color will just write down selection
that color.
But what I want to do as well is I want to change my text and put it bold and put it italic as well.
So what I will do, I will use that with the element.
And in this case, what the element will allow me to do is it will allow me to not be write selection
like I did right there more than once.
So I'll just write down selection.
So I'll start with with and in this case, what I want to use is selection.
And what I want to select on the select front, so we'll work with the fund that is right there, and
then I can write what exactly I want to work with.
So in this case, I'd say I want to work with the color advocates.
So I want to change the color.
So I'll start by changing the color.
All right.
So right now, what we'll do, we are going to change the color in a way that well, in another way.
So instead of writing down the code of the color, we're simply going to use the stick in the way that
I told you that it's possible to work with colors.
We're going to write down VB and then the color that we want.
So in this case, we want to have red.
So let's say we want to use red.
So finally, just write and with.
They were great.
So if you run our function, what's going to happen is that inside of this case, Artex will become
red.
So if we run it, as you can see, the text became red.
And now let's say we want to add more features.
Well, since we work with the with that is right there, we can add more features.
So in this case, that color, we can add that all we can add that italic.
And it's important to write down true in both of them if we want them to work.
There we go.
All right, now we can run everything to see what it looks like, says can see your became bold and
it became in italics.
And we also changed the color of our text, which is pretty cool in my opinion.
So right now, you know how to basically change the colors of your text.
All right.
Let's say right now we want to be able to work with this function, but not on this range.
We can just delete the range.
And now what's going to happen was simply go somewhere.
And when we run our function, it will automatically generate everything, so basically, instead of
having a range where this will work, it will work everywhere.
So basically, if we're on the cell and we run our function, it's going it's going to work.
If we go in another cell, it's going to work as well.
So as you can see right now, simply by deleting the range, what we did is we have made our function
not absolute, but relative.
Well, we created a relative reference to our function, which is pretty cool.
So you can see this is how you can change the colors.
Once again, those are the basics.
You can change colors of a huge amount of cells at once.
You can change colors of just one cell, of two cells of three cells.
You decided.
And right now you know how to implement this.
Well, this element inside of your Excel VBA programming.
So as it first starts, guys, and all in our next class.