How to Write a VBA Code to Create a New Sheet in Excel - learnit

Home Top Ad

Post Top Ad

Wednesday, May 19, 2021

How to Write a VBA Code to Create a New Sheet in Excel

How to Write a VBA Code to Create a New Sheet in Excel

How to Write a VBA Code to Create a New Sheet in Excel

What is Visual Basic for Applications (VBA)?

Visual Basic for Applications (VBA) is an event-driven programming language implemented by Microsoft to develop Office applications. VBA helps to develop automation processes, Windows API, and user-defined functions. It also enables you to manipulate the user interface features of the host applications.


Before we go into further details , let us look at what computer programming is in a layman's language. Assume you have a maid. If you want the maid to clean the house and do the laundry. You tell her what to do using let us say English and she does the work for you. As you work with a computer, you will want to perform certain tasks. Just like you told the maid to do the house chores, you can also tell the computer to do the tasks for you.


The process of telling the computer what you want it to do for you is what is known as computer programming. Just as you used English to tell the maid what to do, you can also use English like statements to tell the computer what to do. The English like statements fall in the category of high-level languages. VBA is a high-level language that you can use to bend excel to your all-powerful will.

Introduction to Visual Basic for Applications

Arithmetic operators - The rules of Brackets of Division Multiplication Addition and Subtraction (BODMAS) apply so remember to apply them when working with expressions that use multiple different arithmetic operators. Just like in excel, you can use

    + for addition

    - for subtraction

    / for division

    * for multiplication


Logical operators - The concept of logical operators covered in the earlier tutorials also apply when working with VBA. These include


If statements

    OR

    NOT

    TRUE

    FALSE

   AND


Table of Content

Sheets.Add Method

Write a VBA Code to ADD a New Sheet in a Workbook
Different Ways to Add New Sheets in a Workbook using a VBA Code

1. Add a Sheet after A Specific Sheet

2.Add a Sheet Before A Specific Sheet

Write a VBA Code to ADD a New Sheet in a Workbook(After)

Example
Sub addsheetafter()
Sheets.add after:=Sheets(“Sheet1”)
End Sub

Write a VBA Code to ADD a New Sheet in a Workbook(Before)

Example
Sub addsheetafter()
Sheets.add Before:=Sheets(“Sheet1”)
End Sub

Please watching My Video is Below

No comments:

Post a Comment

Post Top Ad