How to Write VBA Code in Excel (With Easy Steps)

What Is VBA Code?

We use VBA to write macros that automate simple and complex tasks in Excel. Microsoft Excel users frequently find themselves performing the same set of tasks repeatedly. These tasks can vary in complexity, ranging from simple copy-and-paste operations to more involved ones like data uploads to websites.  We can make these types of tasks to be automated using VBA macros, which reduce the number of manual steps required to one button press.


How to Write VBA Code in Excel: Step-by-Step Procedures

Here is our sample dataset.

how to write vba code in excel


Step 1 – Opening the Visual Basic Tab

  • Go to the Developer tab in the ribbon.
  • Select the Visual Basic tab.
  • The Visual Basic window will be opened.

opening visual basic window to write vba code in excel


Step 2 – Inserting a Module

  • In the Visual Basic tab, click on Insert.
  • Select the Module option.
  • A coding module will appear.

inserting module to write vba code in excel


Step 3 – Writing and Saving Code

  • Insert or write the code in the module.
  • Save the code.


Step 4 – Running Code

  • Click on the Run button or choose the Run command from the Run drop-down menu.

We wrote a simple code that tells by looking at a number whether it is an odd or an even number.

  • Excel will execute your code.

Read More: 20 Practical Coding Tips to Master Excel VBA


Download the Practice Workbook


Related Articles

Get FREE Advanced Excel Exercises with Solutions!
Kawser Ahmed
Kawser Ahmed

Kawser Ahmed is a Microsoft Excel Expert, Udemy Course Instructor, Data Analyst, Finance professional, and Chief Editor of ExcelDemy. He is the founder and CEO of SOFTEKO (a software and content marketing company). He has a B.Sc in Electrical and Electronics Engineering. As a Udemy instructor, he offers 8 acclaimed Excel courses, one selected for Udemy Business. A devoted MS Excel enthusiast, Kawser has contributed over 200 articles and reviewed thousands more. His expertise extends to Data Analysis,... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo