Vba set color font format of cell in Excel

To do it in Excel, here is the answer:

Being able to change the format of a cell with VBA is very useful.

It allows you for example to make the format of a cell or the format of a sheet flexible.

You can adapt the format with the use of a profile different for each user.

  1. Option Explicit
  2. Sub FormatCell()
  3. ActiveCell.Font.Color = RGB(255, 0, 0)
  4. ActiveCell.Interior.Color = RGB(255, 255, 0)
  5. ActiveCell.NumberFormat = "mm/dd/yyyy"
  6. End Sub

Description:

a) Line 3 sets the font color of the cell using RGB code - first argument corresponds to Red, second argument corresponds to Green and 3rd argument corresponds to Blue. In this sample case, cell is set to Red font.

b) Line 4 sets the fill color of the cell using RGB code. In this sample case, cell is set to Yellow fill since Red value of 255 and Green Value of 255 with 0 for Blue correspond to Yellow.

c) Line 5 sets the data in cell to "mm/dd/yyyy" date format.

 

You can find similar Excel Questions and Answer hereunder

1) How to create charts in Excel VBA

2) Conditional formatting with if statement in Excel

3) How do I enter a formula in a cell using VBA (using Relative Reference)?

4) How can I extract file name from a full path including folder path and file name?

5) How do i put double quotes in a string in vba in Excel

6) How can I turn off Alerts using VBA?

7) How to change desktop background in Excel

8) How can I enter a picture in a cell?

9) How can I dynamically add series to an existing chart using VBA?

10) Introduction to tables in Excel VBA and how to use tables, create tables in VBA

 

Here the previous and next chapter