VBA Cells Format – Formatting Excel Cells using VBA

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading...

Formatting Excel Cells can be automated to save a lot of time. Below you can find code samples for formatting Excel cells.

Formatting Cell Interior

You have at least 2 options to set a Cell background color in VBA. The first is setting by using the Color property by setting it to a value using the VBA RGB function and specifying its R (Red), G (Green), B (Blue) components. The second is using the ThemeColor property and setting it to constant representing a default Theme color:

You can read more on the difference between the VBA ColorIndex and VBA Color property here.

Formatting Excel Fonts

Formatting Cell Borders

To set borders of Excel Cells in VBA you need to use the Borders property:

Possible LineStyles:

  • xlContinuous
  • xlDash
  • xlDashDot
  • xlDashDotDot
  • xlDot
  • xlDouble
  • xlSlantDashDot
  • xlLineStyleNone

Possible borders (Index):

  • xlDiagonalDown
  • xlDiagonalUp
  • xlEdgeBottom
  • xlEdgeLeft
  • xlEdgeRight
  • xlEdgeTop
  • xlInsideHorizontal
  • xlInsideVertical

Formatting Cell Alignment

Excel Cell alignment can be modified by a couple of ways. The first is using HorizontalAlignment and VerticalAlignment properties. Additionally you can set indentation using the InsertIndent procedure.

Simply the best place to learn Excel VBA