EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • All Courses
    • All Specializations
  • Blog
  • Enterprise
  • Free Courses
  • All Courses
  • All Specializations
  • Log in
  • Sign Up
Home VBA VBA Resources VBA Tips Programming in Excel
 

Programming in Excel

Udiksha Sable
Article byUdiksha Sable
Madhuri Thakur
Reviewed byMadhuri Thakur

Programming in Excel

Table of Contents
  • What is Programming in Excel?
  • How to do Programming in Excel?
    • Step 1: Enable the Developer Tab
    • Step 2: Record a Macro
    • Step 3: View the VBA Code
    • Step 4: Run the Macro
    • Step 5: Save the File
  • Assigning a Macro to a Command Button

What is Programming in Excel?

Programming in Excel refers to using VBA (Visual Basic for Applications), Excel’s own programming language, that can help you automate tasks and create customized solutions.

When users need to perform repetitive tasks, create complex calculations, or build interactive tools that may be beyond the standard Excel functionality. This is where programming in Excel comes into play.

 

 

How to do Programming in Excel?

Here is a detailed step-by-step tutorial on how you can use Excel programming.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

Step 1: Enable the Developer Tab

  1. Click on File in the top left corner.
  2. Choose Options at the bottom of the left-hand menu.
  3. A new window will pop up. Click on Customize Ribbon on the left.
  4. In the right-hand panel, you will see Developer with a checkbox. Check it.
  5. Click OK at the bottom of the window.

Now, you should see the Developer tab on the Excel ribbon.

Predatory Pricing

Note: For the step-by-step process, check our article on the Developer tab in Excel. It has easy-to-follow steps with pictures.

Step 2: Record a Macro in Excel

1. You can record a macro in three ways:

  • Go to the Developer tab and select Record Macro in the Code groups.
  • Click the View tab and choose Macros.
  • Use the shortcut “Alt+F8“.

Record a Macro in Excel

2. Enter Required Information to Start Recording

  • Macro Name: Enter a name for your macro (no spaces or special characters).
  • Shortcut key (optional): Assign a keyboard shortcut (e.g., Ctrl+j) to run the macro.
  • Description (optional): Add a description to help you remember what the macro does.
  • Store macro in: Choose where to store the macro from the dropdown menu (e.g., “This Workbook” for the current workbook).

Click OK.

Enter Required Information to Start Recording

3. Perform the Actions

In this macro, we are capturing steps to calculate average monthly traffic and highlight above-average months. Here’s what we will do:

  • Format the table:

Enhance the table’s appearance by customizing titles, borders, and background colors and adjusting column width and font size.

Format the table

  • Perform Calculations:

Input formulas for total and average in cells B14 and B15, using SUM and AVERAGE functions, respectively.

Perform Calculations

  • Highlight Cells with Above-Average Traffic:

Use conditional formatting to identify values above the average. In this example, we have highlighted them in green color.

Highlight Cells with Above-Average Traffic

4. Stop Recording

To stop recording, click Stop Recording in the View tab or in the Developer tab under Macros.
Programming in Excel-Stop Recording

Step 3: View the VBA Code

When you record a macro, Excel automatically creates a VBA code for the performed actions. To view or edit the VBA code, follow these steps:

  • To open the VBA Editor, use the shortcut (Alt + F11) or go to the Developer tab > Visual Basic.
  • In the project window, find your workbook (usually named VBAProject – YourWorkbookName).
  • Expand Modules to find your recorded macro.
  • Double-click the module to view the VBA code.

View the VBA Code

Step 4: Run the Macro

To run the macro, you can use either one of the three methods:

  • Use the keyboard shortcut you assigned (Ctrl+j).
  • Go to the Developer tab, click on Macros, select your macro, and click Run.
  • Open VBA Editor > Click on Run > Select Run Sub/UserForm.

Programming in Excel-Run the Macro

Excel will now run the macro and perform the exact steps you performed while recording the macro.

Programming in Excel-Run the Macro 2

Step 5: Save the File

  • Click File > Save As in Excel.
  • Choose the Excel macro-enabled workbook format, name your file, and click Save.

Programming in Excel-Save the File

Why to use “.xlsm”?
The “.xlsm” extension is a special tag telling Excel your workbook has a macro. If you save it as a regular “.xlsx” file, Excel won’t save the macro, and you might lose the code you recorded.

Assigning a Macro to a Command Button

If you want to remove the extra steps of running the macro, you can assign a macro to a command button and automate tasks with a single click. For instance, in our previous example, instead of using the macro directly, we can make a button called “Run.” When you click that button, it will activate the macro.

Here’s a step-by-step process to assign a macro to a command button:

Step 1: Insert a Command Button

  • Click the Developer tab.
  • Click the Insert button in the Controls groups.
  • From the ActiveX Controls section, select Command Button (it looks like a button icon).
  • Click on your Excel worksheet where you want to place the command button. This will add the button.

Programming in Excel-Insert a Command Button

Step 2: Assign a Macro to the Command Button

  • Right-click on the newly inserted command button and select View Code. This will open the VBA Editor.

Assign a Macro to the Command Button

  • Add the code you want to the VBA Editor. We are adding the following:
Private Sub CommandButton1_Click()
Range("A1").Value = "Welcome to EDUCBA Family"
Range("A2").Value = " We're glad to have you"
End Sub

Assign a Macro to the Command Button 2

Step 3: Use the Command Button

  • Close the Editor and come back to Excel.
  • Click the Design Mode button in the Developer tab to switch it off.
  • Click the command button you inserted. It should execute the macro you assigned, in this case, displaying the message box.

Programming in Excel-Use the Command Button

Frequently Asked Questions (FAQs)

Q1. When can I use VBA and macros?
Answer: You can use VBA to,

  1. Automate tasks like report generation, data entry, and complex calculations.
  2. Customize Office apps with menus, dialog boxes, and forms for a better user experience.
  3. For data manipulation and analysis, especially in Excel.
  4. Integrate Office apps and automate data transfers.

Q2. Can I use VBA without knowing how to code?
Answer: Yes, you can easily use VBA without actually knowing how to write VBA code. As we saw in the earlier section, “Step 3: View the Code”, Excel automatically generates VBA code. You only have to record the macro’s actions and create macros without writing complex code. However, you can change the VBA code if any changes are required. Thus, this approach is user-friendly and requires minimal programming expertise.

Q3. Is VBA a hard language?
Answer: VBA is not a very difficult language. However, learning VBA depends on prior programming experience and specific requirements. You can easily learn VBA by reading this article or taking a course.

Recommended Articles

We hope this article on programming in Excel taught you what you were looking for. For more VBA-related articles, check the following:

  1. VBA UserForm
  2. VBA IF Statements
  3. VBA Loops
  4. VBA Input
Primary Sidebar
Footer
Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA
Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Web Development & many more.

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW