vba set color font format of cell in Excel

Q155. In Excel, how can I set the fill color, font color and set number format of cell to date?

excel vba set color font format of cell

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


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 can I remove display of Gridlines in my worksheet using VBA?

2) How can I clear all formats (formats alone not data) from a range of cells?

3) Highlight row of selected cell in Excel

4) How can I add and link a Chart Title to a cell value?

5) I want to add a trend indicator symbol next to my sales data - how can I do that?

6) How can I enter multiple lines of data in a cell?

7) How can I convert Column numbers into Column names for use in range definition?

8) How do I assign a macro to a shape using VBA?

9) How can I add a Timestamp after macro execution?

10) How can I prevent users from seeing / accessing my macro code?

11) How can I delete all shapes in a WorkSheet?

12) Determine if hyperlinks are valid in Excel

13) How can I identify all cells with Data Validation in my WorkSheet?

14) Remove the apostrophe cell text values in Excel

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