VBA – Formatting Cells

Formatting Cells

You can use a macro in formatting cells, which involves using the Range Properties discussed earlier on. There are many properties we can use to edit cells, such as the cell size (the height, the width), cell color, font etc.

As an example, we will change the cell color to green if the inputted value is a number and bring a Notification if otherwise. Then also change the font of the cell.

Now, open another Editor window and add the following macros to the ones written in the previous example:

VBA - Formatting Cells

Fig2.5: Macros to for formatting the selected cells

VBA - Formatting Cells

Fig 2.6: Macros for Selecting, Formatting and Populating the Selected cells

Some simple programming and VBA concepts were used in the macros above. Stuffs like IsNumeric; which checks if our input value is a number (Numeric). It is a method in Excel (it performs an action). Also, the “If End If” is a conditional statement and it is a programming concept to check the condition of a statement.

Next Section: Color ColorIndex

Was this article helpful?

Related Articles

Leave a Reply