In this blog post, you will learn about how to change the
font color in Excel VBA.
Suppose that we have some text dataset from range “A1: B6”, and want to change the color of this.
See below text dataset image:-
Here we have two methods to change the “Font” color of a dataset.
First
Method: Font.Color
Second Method: Font.ColorIndex
See below both the method explained one by one.
First Method: Font.Color
This is our first method to change the “Font” color of our
dataset.
First of all, go to the Developer tab in Excel.
Once the “Visual Basic” window opens then Go to “Insert” and
open a new “Module”.
The new “Module” opens.
Then write the following code:-
Because here, in the above image our dataset exists between
range “A1: B6”.
So our VBA code will be:-
“Range ("A1: B6").Font. Color = vbRed” and then
press “F8”. See the font color has been changed.
In this method, we have 8 standard colors to change the font
color of our dataset.
See below all 8 standard colors, write these codes in Excel
Visual Basic Editor and run it by pressing “F8” (step by step).
See the text color changed one by one.
Second Method: Font.ColorIndex
In this method, we have more options to change the “Font”
color of our dataset.
Now again, we will follow the same way to enter into the
visual basic editor.
In the previous method, we can change the font with 8
standard colors only.
In
this method (Font.ColorIndex), every single number from 1 to 56, is assigned a
particular color.
See in the below image, here are some random number applied.
You can apply for the number up to 56.
So, these are the two methods to change the “Font” color of a
text or a text dataset.
I hope you find this useful.
Please feel free to put our comments.
Regards
No comments:
Post a Comment