What is VBA

VBA stands for Visual Basic for Applications, an event-driven programming language from Microsoft. It is now predominantly used with Microsoft Office applications such as MSExcel, MS-Word and MS-Access.

Prerequisites

Before proceeding with this tutorial, you should install MS Office, particularly MS-Excel.

Application of VBA

You might wonder why to use VBA in Excel as MS-Excel itself provides loads of inbuilt functions. MS-Excel provides only basic inbuilt functions which might not be sufficient to perform complex calculations. Under such circumstances, VBA becomes the most obvious solution.
For example, it is very hard to calculate the monthly repayment of a loan using Excel's built-in formulas. Rather, it is easy to program a VBA for such a calculation.

Accessing VBA Editor

In Excel window, press "ALT+F11". A VBA window opens up as shown in the following screenshot.
image1

VBA - Excel Macros

In this chapter, you will learn how to write a simple macro in a step by step manner.
Step 1:-First, enable 'Developer' menu in Excel 20XX. To do the same, click File → Options.
Step 2:-Click ‘Customize the Ribbon’ tab and check 'Developer'. Click 'OK'.
image2
Step 3:-The 'Developer' ribbon appears in the menu bar.
image3
Step 4:-Click the 'Visual Basic' button to open the VBA Editor.
image4
Step 5:-Start scripting by adding a button. Click Insert → Select the button.
image5
Step 6:-Perform a right-click and choose 'properties'.
image6
Step 7:-Edit the name and caption as shown in the following screenshot.
image7
Step 8:-Now double-click the button and the sub-procedure outline will be displayed as shown in the following screenshot.
image8
Step 9:-Start coding by simply adding a message.

Private Sub say_helloworld_Click()
MsgBox "Hi"
End Sub

Step 10:-Click the button to execute the sub-procedure. The output of the sub-procedure is shown in the following screenshot. Make sure that you do have design mode turned on. Simply click it to turn it on if it is not on.
image9

How to color the background with button

Search vba color index on Google and you will get the all color codes
After completing till Step-10 write this code:-
Cells.Interior.ColorIndex=3