What is a active sheet in excel

By keyboard: First, press F6 to activate the sheet tabs. Next, use the left or right arrow keys to select the sheet you want, then you can use Ctrl+Space to select that sheet. Repeat the arrow and Ctrl+Space steps to select additional sheets.

Contents

  • 1 How do you activate a sheet?
  • 2 How do I make a sheet active in Excel VBA?
  • 3 What is active in Excel?
  • 4 How do you select an active cell in Excel?
  • 5 How do you activate a workbook and worksheet?
  • 6 What is worksheet activate event?
  • 7 What is active sheet in VBA?
  • 8 How do you make a cell A1 active cell?
  • 9 How do I select a column until the end in Excel?
  • 10 How do I activate cells in Excel using the keyboard?
  • 11 How do I make a workbook active?
  • 12 How do you set an active workbook?
  • 13 What are the differences between workbooks worksheets and spreadsheets?
  • 14 How do I activate an inactive sheet in Excel?
  • 15 When can a worksheet change event be triggered?
  • 16 How do you run a macro when a sheet is activated?
  • 17 How do I find the active sheet name?
  • 18 How do you active the cell?
  • 19 What is an active cell in Calc?
  • 20 Which is the active cell in the spreadsheet above?

How do you activate a sheet?

Only one Sheet may be active at a time.

  1. Activate Worksheet (Setting the ActiveSheet)
  2. ActiveSheet Name.
  3. Select Worksheet by Tab Name.
  4. Select Worksheet by Index Number.
  5. Select Worksheet With VBA Code Name.
  6. Select Current Worksheet.
  7. Set ActiveSheet to Variable.
  8. Change ActiveSheet Name.

VBA Activate Worksheet Method- Instructions

  1. Open an Excel Worksheet.
  2. Press Alt+F11 :This will Open the VBA Editor.
  3. Insert a Module from Insert Menu.
  4. Copy the above code for activating worksheet and Paste in the code window(VBA Editor)
  5. Save the file as macro enabled Worksheet.

What is active in Excel?

An active cell refers to the currently selected cell in a spreadsheet.Whenever you click on a specific cell within a spreadsheet, it becomes the active cell. Once a cell is selected, you can enter values or a function into the cell.

How do you select an active cell in Excel?

Press CTRL+A. Note If the worksheet contains data, and the active cell is above or to the right of the data, pressing CTRL+A selects the current region. Pressing CTRL+A a second time selects the entire worksheet.

How do you activate a workbook and worksheet?

You may want to Activate Workbook Or Work Sheet.
Instructions:

  1. Open an excel workbook.
  2. Press Alt+F11 to open VBA Editor.
  3. Insert a new module from Insert menu.
  4. Copy the above code and Paste in the code window.
  5. Press F5 to see the output.
  6. You should see Aactivated workbook and Worksheet.
  7. Save the file as macro enabled workbook.

What is worksheet activate event?

Occurs when a workbook, worksheet, chart sheet, or embedded chart is activated.

What is active sheet in VBA?

VBA Assumes the Active Workbook and Active Sheet
The ActiveSheet is the worksheet tab that is currently selected before running the macro. If multiple sheets are selected, the ActiveSheet is the sheet that is currently being viewed.

How do you make a cell A1 active cell?

Active cell overview
When you first start Excel the active cell is the first cell, which is always A1. You can move the cell pointer by pressing the arrow keys or Enter on your keyboard, or you can click any cell using your computer mouse. If you’re using the keyboard, you can also press the F2 to edit the active cell.

How do I select a column until the end in Excel?

To select to end of column from a cell, use excel shortcut Ctrl+Shift + Down arrow.

How do I activate cells in Excel using the keyboard?

First, the keyboard shortcut for editing a cell is F2 on Windows, and Control + U on a Mac. With Excel’s default settings, this will put your cursor directly in the cell, ready to edit. You can also double-click a cell to edit.

How do I make a workbook active?

Steps to Activate a Workbook
Specify the workbook name in the double quotation marks. Enter a dot (.) to get the list of properties and methods. Select the Activate method from the list or you can also type it. In the end, run the code to activate the workbook.

How do you set an active workbook?

VBA Activate Workbook – Instructions

  1. Open an Excel Workbook.
  2. Press Alt+F11 to Open VBA Editor.
  3. Insert a Module from Insert Menu.
  4. Copy the above code for activating a range and Paste in the code window(VBA Editor)
  5. Save the file as macro enabled workbook.

What are the differences between workbooks worksheets and spreadsheets?

The worksheet is single page spreadsheet or page in Excel, where you can write, edit and manipulate data, whereas the collection of such worksheets is referred as a workbook. It is very similar to a single page (worksheet) and a complete book (workbook).

How do I activate an inactive sheet in Excel?

Click the tab for the first sheet, then hold down CTRL while you click the tabs of the other sheets that you want to select. By keyboard: First, press F6 to activate the sheet tabs. Next, use the left or right arrow keys to select the sheet you want, then you can use Ctrl+Space to select that sheet.

When can a worksheet change event be triggered?

In Excel a Worksheet Change Event is a trigger for a macro when a cell or group of cells change. I will start out by showing how a change to a single cell can trigger an action. The following will colour cell B2 Red whenever the cell changes.

How do you run a macro when a sheet is activated?

Running a Macro when a Worksheet is Activated

  1. Display the VBA Editor by pressing Alt+F11.
  2. In the Project window, at the left side of the Editor, double-click on the name of the worksheet that you want to affect.

How do I find the active sheet name?

To get the name the active sheet: var actualSheetName = SpreadsheetApp. getActiveSpreadsheet(). getActiveSheet().

How do you active the cell?

First method is by double clicking on the cell that you want to put into edit mode. This is the most common and perhaps the most used method. Double clicking on a cell will simply activate and make it editable. You can also make a cell editable by clicking in the formula bar.

What is an active cell in Calc?

An active cell refers to the currently selected cell in a spreadsheet.Whenever you click on a specific cell within a spreadsheet, it becomes the active cell. Once a cell is selected, you can enter values or a function into the cell.

Which is the active cell in the spreadsheet above?

In an Excel worksheet, each small rectangle or box is known as a cell. The active cell is the selected cell in which data is entered when you begin typing. Only one cell is active at a time. The active cell is the cell surrounded by a black border.

Skip to content

VBA ActiveSheet – Excel Active Sheet Object

  • ActiveSheet VBA in Excel

VBA ActiveSheet Object helps to refer the currently activated sheet in the active workbook. We can get all properties and methods of the ActiveSheet using VBA. Let us see the useful of the examples on Excel VBA ActiveSheet Object.

What is Active Sheet in Excel VBA?

Worksheet which is currently activated in the Active Workbook and Active Window is referred as Active Sheet. You can make any Worksheet as Active Worksheet by Activating a Worksheet. You can use Activate Method of Worksheet to activate a sheet using Excel VBA.

Sheets("SheetName").Activate

Set a Worksheet as Active Sheet in VBA

You can use Activate method to set worksheet as active sheet in VBA. For example, you can set the Sheet 3 as active sheet by calling the Activate Method.

Sheets(3).Activate

Reading the Data from ActiveSheet

We can use the VBA to read the data from ActiveSheet Object. We can use all the methods and properties of a worksheet Object. For example, the following example get the data from ActiveSheet and show it in a message box.

Sub sbGetDataFromActiveSheet()
MsgBox ActiveSheet.Range("D5")
End Sub

The code statement ActiveSheet.Range(“D5”) is reading the data from Range D5 of ActiveSheet. It is not mandatory to specify the ActiveSheet befor Range object in the above macro. Range(“D5”) also refer the data from ActiveSheet.

Then, when do we use ActiveSheet Object in Real-time projects?

Uses of ActiveSheet in VBA Development

We deal with multiple worksheets while automating an Excel Task. We can simply set the ActiveSheet to a variable and keep it fro future reference.

For example: Let us say, we have 3 worksheets in the Workbook and currently you have activated Sheet 2 and You wants to move into Sheet 3 and refer the Sheet2 Data. You can use the ActiveSheet Object in this scenario.

Sub sbGetDataFromActiveSheet()
'You wants to work on Sheet 2
Sheets(2).Activate
'Reading the Data from ActiveSheet Range A1
K = Range("A1")

'Now you wants to move into Sheet 3.
'Let us set the ActiveSheet into a temporary variable before activating the sheet 3
Set sht = ActiveSheet

'Now activate Sheet 3
Sheets(3).Activate

'Enter Data from Range D3 of Sheet 2 in Range A1 of Sheet 3
Range("A1") = sht.Range("D3")
End Sub

Get the Name of the ActiveSheet

You can use the .Name property of the ActiveSheet object to return the ActiveSheet Name using VBA.

Sub sbActiveSheetName()
MsgBox ActiveSheet.Name
End Sub

Copy the Data from Other Sheet and Paste in the ActiveSheet

We can copy the data from a worksheet (it can be the same sheet or a different sheet)  and paste in the ActiveSheet.

Sub sbCopyFromOtherSheetAndPasteInActiveSheet()
Sheets(2).Activate
Sheets(3).Range("A1:G25").Copy
Range("G1").Select
Activeheet.Paste
End Sub

The above macro will Activate the Sheet 2. And copy the data from Sheet 3 and Paste at Range G1 of the ActiveSheet.

Count Shapes in ActiveSheet

The following macro will return the number of shapes in ActiveSheet.

Sub sbCountShepsInActiveSheet()
MsgBox Activeheet.Shapes.Count
End Sub

Count Charts in ActiveSheet

The following macro will return the number of Chart Objects in ActiveSheet.

Sub sbCountChartsInActiveSheet()
MsgBox Activeheet.ChartObjects.Count
End Sub

Protect in ActiveSheet using VBA

You can use the Protect Method of ActiveSheet to password protect the Sheet.

Sub sbProtectSheet()
    ActiveSheet.Protect "password", True, True
End Sub

UnProtect: You can use unprotect method of Activesheet to unprotect the sheet.

    ActiveSheet.UnProtect "password"
Effortlessly Manage Your Projects and Resources
120+ Professional Project Management Templates!

A Powerful & Multi-purpose Templates for project management. Now seamlessly manage your projects, tasks, meetings, presentations, teams, customers, stakeholders and time. This page describes all the amazing new features and options that come with our premium templates.

Save Up to 85% LIMITED TIME OFFER
Excel VBA Project Management Templates
All-in-One Pack
120+ Project Management Templates
Essential Pack
50+ Project Management Templates

Excel Pack
50+ Excel PM Templates

PowerPoint Pack
50+ Excel PM Templates

MS Word Pack
25+ Word PM Templates

Ultimate Project Management Template

Ultimate Resource Management Template

Project Portfolio Management Templates

Related Posts

    • What is Active Sheet in Excel VBA?
    • Set a Worksheet as Active Sheet in VBA
    • Reading the Data from ActiveSheet
    • Uses of ActiveSheet in VBA Development
    • Get the Name of the ActiveSheet
    • Copy the Data from Other Sheet and Paste in the ActiveSheet
    • Count Shapes in ActiveSheet
      • Count Charts in ActiveSheet
    • Protect in ActiveSheet using VBA

VBA Reference

Effortlessly
Manage Your Projects

120+ Project Management Templates

Seamlessly manage your projects with our powerful & multi-purpose templates for project management.

120+ PM Templates Includes:

Effectively Manage Your
Projects and  Resources

With Our Professional and Premium Project Management Templates!

ANALYSISTABS.COM provides free and premium project management tools, templates and dashboards for effectively managing the projects and analyzing the data.

We’re a crew of professionals expertise in Excel VBA, Business Analysis, Project Management. We’re Sharing our map to Project success with innovative tools, templates, tutorials and tips.

Project Management
Excel VBA

Download Free Excel 2007, 2010, 2013 Add-in for Creating Innovative Dashboards, Tools for Data Mining, Analysis, Visualization. Learn VBA for MS Excel, Word, PowerPoint, Access, Outlook to develop applications for retail, insurance, banking, finance, telecom, healthcare domains.

Analysistabs Logo

Page load link

VBA Projects With Source Code

3 Realtime VBA Projects
with Source Code!

Take Your Projects To The Next Level By Exploring Our Professional Projects

Go to Top

The ribbon, tabs, commands gridlines, control buttons, etc. that a user can see and interact with on the screen after opening an Excel spreadsheet are called User Interface Environment in MS Excel.

Excel is an electronic spreadsheet program, developed by Microsoft Corporation.  An Excel Spreadsheet is used to record, validate and analyze the numeric data for maintaining Payrolls, Selling and purchasing product orders, Progress Reports, family budgets, and more.

These are calculated whether using general, financial, logical, statistical, engineering or other functions and formulas. The features in the excel environment are explained below in the screenshot.

User Interface Environment in MS Excel​
User Interface Environment in MS Excel​

Table of Contents

  • User Interface to MS Excel
    • Quick Access Toolbar:
    • File Menu:
    • Tell me:
    • Title Bar:
    • Sign in:
    • Share:
    • Control Buttons:
    • Ribbon:
    • Ribbon Display Options:
    • Tabs:
    • Groups:
    • Commands
    • Name Box:
    • Insert Functions:
    • Formula bar:
    • Row and Column Headings:
    • Vertical/Horizontal Scrollbar:
    • Page View Options:
    • Zoom Slider/Toolbar:
    • Click to Select All:
    • Gridlines:
    • Cell in Excel:
    • Cell Address:
    • Active Cell:
    • Active Sheet/sheet tab:
    • Range of cells:
    • Sheet tabs:
    • Insert New Worksheet:

Quick Access Toolbar:

The Quick Access Toolbar appears at the top left corner of the Excel application and other MS Office suites. The default commands of the Quick Access Toolbar are Save, Undo and Redo.

In the graphical user interface environment in MS Excel, the File menu is also known as the File Tab, used to control and access the file functions of the MS Office suite.

Officially, it handles files using the file menu commands such as new, open, save, save, print, share, export, publish, close, account and options. To read the File menu features in an Excel environment click here.

Tell me:

In the user interface of Microsoft Excel, the tell me to search box helps you search the command quickly and easily without going to the ribbon tab or group. Here you can type any command name you want to use or apply to the Sheet/Document. 

Title Bar:

You can see the title bar at the top of the excel spreadsheet application (MS Office suites) with the name currently being used. The name of the workbook appears in the middle of the title bar. The name of the workbook here we called is a title.

Sign in:

Microsoft’s free account is used to purchase, activate, and access Microsoft services. You can save and receive your documents from anywhere using the service. You can also use this account to use and access OneDrive, Skype, and Microsoft store.

This option appears at the top right corner, underneath the close button, you can save your work on different platforms by sharing with caring. These Platforms are Google Cloud, One Drive, E-mail, Blogs, people, etc.

Control Buttons:

The Minimize, Restore Down/Maximize and Close buttons are called Control Buttons. These appear at the top right corner of the (MS Office Suite of Applications) Excel Spreadsheet.

Ribbon:

Ribbon in Excel
Ribbon in Excel

The Ribbon is a collection of groups, commands and functions and locates under each Tab such as Home, Insert, Design, Layout, References, Mailings, Review and View, It is designed to help you quickly and easily find the groups and commands to complete a task you want.

Ribbon Display Options:

Ribbon Display Options
Ribbon Display Options

The Ribbon Display options are located at the right corner of the title bar and the 4th position on the left of the Control buttons.  The Ribbon Display Options include Auto-Hide Ribbon, Show Tabs, Show Tabs and Commands. 

Tabs:

Tabs or Menus​
Tabs or Menus​

Home, Insert, Page Layout, Formulas, Data, Review, and view are called Tabs. Each tab is a form of group. Similarly, each Group is a form of the command.

Groups:

Groups in excel
Groups in excel

Each tab is a form of group. Similarly, each group is a form of the command. For example, Groups on the Home tab include Clipboard, Font, Alignment, Number, Style, Cells, and Editing.

Commands

Commands in Microsoft MS Excel
Commands in Microsoft MS Excel

A command is part of a group. And access to a specific piece of work. For example, the Font group commands include bold, italic, underline, etc.

Name Box:

It is the reference (address) for a specific cell or range of cells or you can set the name for a particular cell or range of cells in an excel spreadsheet.

Insert Functions:

It helps to get the result by using a particular function based on its arguments. This is one of the features of Excel.

Formula bar:

In the Formula bar, you can view and modify the function or formula that applies to any cell in the sheet for any calculation.

Row and Column Headings:

The column is a collection of Vertical light grey coloured lines containing the letters used to identify each column in a worksheet.

The column heading appears on the top of it (above the first row). The row is a collection of Horizontal light grey coloured lines containing the number used to identify each row in a worksheet. The Row Heading appears at the beginning of it (left of the first column).

Without Row and Column Headings in excel you cannot perform an autofill feature.

Vertical/Horizontal Scrollbar:

The scrollbar is used to view the worksheet in any part by using the Vertical or Horizontal scrollbar whether by moving up, down, left or right.

Page View Options:

Page View Options appear at the right but one on the taskbar. These are

Normal: Normal is a default view and is easier to work in this mode in the worksheet.

Page Layout: In the Page Layout mode, the worksheet is divided into more page sizes for print preview.

Page Break Preview: The Page Break Preview shows the worksheet as separate pages where there are the contents to see how a page look likes.

Zoom Slider/Toolbar:

To zoom in and out excel spreadsheet in the desired size, use the Zoom slider, which appears at the bottom right corner of the workbook.

Click to Select All:

Click on the top left of the common area (Under the Name Box) of the Column and Row Headings to select the entire worksheet. Just like Ctrl + A.

Gridlines:

The Gridlines are the collection of Horizontal and Vertical light grey coloured lines in a worksheet.

Cell in Excel:

In the Microsoft Excel Spreadsheet Environment, A cell is an Intersection of Rows and columns to form like a rectangle in a worksheet.

Cell Address:

The location of a cell is identified by its column letter and the row number is called, cell address or cell reference.

Active Cell:

An Active Cell in the graphical user interface is where it is bold with a dark outline. An Active cell is an identifiable mark that can be accepted to enter and edit the content.

Active Sheet/sheet tab:

For a selected worksheet that is currently being used, the name of the sheet tab is in bold and appears at the bottom left corner of the workbook.

Range of cells:

In the Microsoft Excel Spreadsheet Environment, More than two cells that are selected horizontally or vertically are called a range of cells.

Sheet tabs:

In the user interface environment in MS Excel, The name of the sheets that appears from the bottom left corner of the worksheet are called sheet tabs.

Insert New Worksheet:

To insert more worksheets in a workbook, click the insert sheet tab button, located right to the sheet tabs.

  1. What is an Active cell in Excel?

    An Active Cell is where it is bold with a dark outline. An Active cell is an identifiable mark that can be accepted to enter and edit the content.

  2. What is an active Sheet?

    For a selected worksheet that is currently being used, the name of the sheet tab is in bold and appears at the bottom left corner of the workbook.

  3. What is the range of cells in excel?

    In the Microsoft Excel Spreadsheet Environment, More than two cells that are selected horizontally or vertically are called a range of cells.

  4. What is the sheet tab in excel?

    In the Microsoft Excel Spreadsheet Environment, The name of the sheets that appears from the bottom left corner of the worksheet is called sheet tabs.

  5. What is a cell Address in Excel?

    The location of a cell is identified by its column letter and the row number is called, cell address or cell reference.

  6. What are Gridlines in Excel?

    The Gridlines are the collection of Horizontal and Vertical light grey-coloured lines in a worksheet.

  7. What is Formula Bar in Excel?

    In the Formula bar, you can view and modify the function or formula that applies to any cell in the sheet for any calculation.

  8. What is Insert Function in Excel?

    It helps to get the result by using a particular function based on its arguments. This is one of the features in excel.

  9. What is Name Box in Microsoft Excel?

    If you can see the reference (address) for a specific cell or range of cells or you can set the name for a particular cell or range of cells in an excel spreadsheet.

In this post, you’ll be learning how you can select a worksheet and activate it using Excel VBA.

ActiveSheet in Excel

The term ActiveSheet, refers to the currently active Worksheet in Excel VBA.

Let’s see in detail about the active sheet command.

To run the code,

  • Under the developer tab, click visual basic

  • Click the insert option and choose module
  • Enter your code and click run.

How to Activate or Set the WorkSheet in Excel VBA?

To set the ActiveSheet use Worksheet.Activate:

Worksheets("Sheetname").Activate

This sheet will activate a new worksheet in the current workbook.

If you want to activate an existing sheet,

ActiveSheet Name

To get the ActiveSheet Name, use the property ActiveSheet.name in Excel VBA.

ActiveSheet Name

Selected Sheets vs ActiveSheet in Excel VBA

At any point in time, only one Sheet can be the ActiveSheet in Excel VBA.But, multiple Worksheets can be selected at once.

If multiple Worksheets are selected, then the Worksheet with top most priority is considered as active sheet.

Select Worksheet

If you want to select a worksheet instead of activating it you can use .select  in the above codes instead of activate command.

Select Worksheet by Tab Name

This code line selects a Worksheet based on its Sheet Tab Name

Sheets("Select sheet).Select

Select Worksheet by Index Number

This code line selects a Worksheet based on its position relative to other tabs

Select Worksheet with VBA Code Name

To select worksheet using VBA code name, enter the following code

Selecting worksheets by code name will prevent errors.

Select Current Worksheet

To select the current Worksheet, you can use the ActiveSheet object:

Change ActiveSheet Name

To change the active sheet name

ActiveSheet.Name = "New active sheet"

GoTo Next Sheet

To go to next sheet, enter the following code. If the active sheet is the last sheet, this command will go to the first sheet.

If ActiveSheet.Index = Worksheets.Count Then

    Worksheets(1).Activate

Else

    ActiveSheet.Next.Activate

End If

Return to VBA Code Examples

In this Article

  • ActiveSheet
    • Activate Worksheet (Setting the ActiveSheet)
    • ActiveSheet Name
  • Selected Sheets vs ActiveSheet
  • Select Worksheet
    • Select Worksheet by Tab Name
    • Select Worksheet by Index Number
    • Select Worksheet With VBA Code Name
    • Select Current Worksheet
  • More Activate / Select Sheet Examples
    • Set ActiveSheet to Variable
    • Change ActiveSheet Name
    • With ActiveSheet
    • Loop Through Selected Sheets
    • GoTo Next Sheet
  • VBA Coding Made Easy

This article will discuss the ActiveSheet object in VBA. It will also discuss how to activate, select, and go to Worksheets (& much more). Read our full VBA Worksheets Guide for more information about working with worksheets in VBA.

ActiveSheet

In VBA, ActiveSheet refers to the currently active Worksheet. Only one Sheet may be active at a time.

Activate Worksheet (Setting the ActiveSheet)

To set the ActiveSheet use Worksheet.Activate:

Worksheets("Input").Activate

The Activate Sheet command will actually “go to” the sheet, changing the visible Sheet.

vba activate sheet

The above example uses the Sheet (Tab) name.  Instead you can use the VBA code name for the worksheet:

Sheet1.Activate

vba activesheet

ActiveSheet Name

To get the ActiveSheet Name:

msgbox ActiveSheet.name

Selected Sheets vs ActiveSheet

At any point in time, only one Sheet can be the ActiveSheet. However, multiple Worksheets can be selected at once.

When multiple Worksheets are selected only the “top-most” Worksheet is considered active (the ActiveSheet).

vba selected sheets

Select Worksheet

If you would like to select a worksheet instead of activating it. Use .Select instead.

Select Worksheet by Tab Name

This selects a Worksheet based on it’s Sheet Tab Name

Sheets("Input").Select

vba select sheet

Select Worksheet by Index Number

This selects a Worksheet based on it’s position relative to other tabs

Worksheets(1).Select

vba select sheet index number

Select Worksheet With VBA Code Name

Sheet1.Select

Selecting worksheets by code name can prevent errors caused by worksheet name changes.

Select Current Worksheet

To select the current Worksheet, use the ActiveSheet object:

ActiveSheet.Select

More Activate / Select Sheet Examples

VBA Programming | Code Generator does work for you!

Set ActiveSheet to Variable

This will assign the ActiveSheet to a Worksheet Object Variable.

Dim ws As Worksheet

Set ws = ActiveSheet

Change ActiveSheet Name

This will change the ActiveSheet Name.

ActiveSheet.Name = "NewName"

With ActiveSheet

Using the With Statement allows you to streamline your code when working with objects (such as Sheets or ActiveSheet).

With ActiveSheet
    .Name = "StartFresh"
    .Cells.Clear
    .Range("A1").Value = .Name
End With

Notice how you don’t need to repeat “ActiveSheet” before each line of code. This can be a huge time saver when working with a long list of commands.

Loop Through Selected Sheets

The following macro will Loop through all selected sheets, displaying their names.

Sub GetSelectedSheetsName()
    Dim ws As Worksheet

    For Each ws In ActiveWindow.SelectedSheets
         MsgBox ws.Name
    Next ws

End Sub

GoTo Next Sheet

This code will go to the next Sheet. If the ActiveSheet is the last Sheet, then it will go to the first Sheet in the Workbook.

If ActiveSheet.Index = Worksheets.Count Then
    Worksheets(1).Activate
Else
    ActiveSheet.Next.Activate
End If

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro – A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users!

Select Activate Worksheet

Learn More!

<<Return to VBA Examples

What is VBA Activesheet Property?

The active sheet means the current worksheet which you are
working on and viewing. The ActiveSheet object signifies the worksheet tab that
is selected before running the VBA code. If the user is working with multiple
sheets, then the currently viewed files are considered as the active sheet. VBA
facilitates many properties and methods that can be called using the
ActiveSheet object.

By Default, Excel considered the only topmost worksheet as
the ActiveSheet, and all the VBA coding is applicable only for the topmost
worksheet. The user can mark or align any Excel worksheet as the Active sheet
by calling the Activesheet object with the sheet name. One can also use the VBA
Activate method to activate any Excel sheet.

People often confuse the Active worksheet with the selected
sheet and use them interchangeably. But both have different
functionalities.  Let’s evaluate the
difference below:

Selected Worksheet  Active Worksheet
Selected Worksheet can select one or more Excel Worksheets
within an Excel Window.
 
Active Worksheet only selects the current Worksheet to view and work
upon.
 
Each Workbook can have multiple Selected Worksheets At a time, only one active sheet can be selected.

Importance of Using ActiveSheet Object

  1. This property is useful when a user wants to use
    another sheet (to run the VBA code and modify the objects apart from the
    topmost worksheet.
  2. Many times we automate an Excel task with the
    help of multiple worksheets. In this situation, we can use Activesheet property
    to set the Activesheet variable and practice it for future reference.

Syntax

expression.ActiveSheet

where the expression variable
represents an application object.

Return

This property returns a sheet object representing the active
sheet in the current Excel Workbook. It returns null if the worksheet has no active
sheet.

Read Data from ActiveSheet

One of the basic tasks in VBA’s day to day life is to read
data from Excel ActiveSheet. The worksheet’s range object can be used to read
data from the ActiveSheet Object.

Although, if you are referring to the topmost sheet,
then it’s not necessary to specify ActiveSheet function before Range
object.  In the below code Range (“B5”)
can also read the data from ActiveSheet.

Code:

Sub ActiveSheet_ReadProperty()
 'reading the value of B5 cell in the ActiveSheet
 'with the help of Range object
 MsgBox ActiveSheet.Range("B5")
 'if ActiveCell object is not specified
 MsgBox Range("B5") 'it will return the same value as above
 End Sub 

Let’s work with the set-by-step code of lines:

Step 1: Open the VBA developer tab either by using
the shortcut keywords Alt +F11 or click on developer window -> visual basic
editor.

Step 2: Visual Basic Editor will open. Next step is
to create a module. Right-clicking on the VBA Project-> Click on Insert->
Click on Module.

VBA ActiveSheet

Step 3: In the Module window, introduce the sub-block,
followed by your macro name.

VBA ActiveSheet

Step 4: We will call the ActiveSheet function and to read
the data will specify the Range object (specifying the cell or range in it.

VBA ActiveSheet

Step 5: With the help of ‘Msgbox’ will display the output.

VBA ActiveSheet

Step 6: We will repeat the above 2 steps, but this time
will not specify the ActiveSheet object.

VBA ActiveSheet

Output

Step 7: Execute the above code either by pressing the F5
shortcut key or by clicking on the Run button.

Step 8: You will notice that the output has been displayed in
the message box.

VBA ActiveSheet

Step 9: Press OK. Again, the message box dialog will be
displayed, and both the outputs will be the same.

VBA ActiveSheet

ActiveSheet Name

The VBA  ‘.Name
‘property of the ActiveSheet fetches the name of your sheet. With the help of
the name, you can proceed with many applications.

Code:

Sub ActiveSheet_NameProperty()
 'fetching the name of the ActiveSheet with help of
 'ActiveSheet.Name property
 MsgBox "The name of ActiveSheet is" & ActiveSheet.Name
 End Sub 

Let’s work with the set-by-step code of lines:

Step 1: Open the VBA developer tab either by using
the shortcut keywords Alt +F11 or click on developer window -> visual basic
editor.

Step 2: Visual Basic Editor will open. Next step is
to create a module. Right-clicking on the VBA Project-> Click on Insert->
Click on Module.

VBA ActiveSheet

Step 3: In the Module window, introduce the sub-block,
followed by your macro name.

VBA ActiveSheet

Step 4: With the help of MsgBox, we will display the
name by using VBA ActiveSheet.Name property.

VBA ActiveSheet

Output

Step 5: Execute the above code either by pressing the
F5 shortcut key or by clicking on the Run button.

Step 6: You will notice that the name has been
displayed in the MsgBox.

VBA ActiveSheet

Password Protection in ActiveSheet

You can secure your ActiveSheet from unintended users and
safeguard your data by using the VBA protect method. It will set a password in
your current sheet. If needed, you can even remove it by using the VBA
UnProtect method.

Syntax

  1. Protect Data
ActiveSheet.Protect ([Password], [DrawingObjects], …)
  • UnProtectData
ActiveSheet.UnProtect “password”

Code:

Sub ActiveSheet_ProtectProperty()
 'protect method is used to secure the
 'ActiveSheet with password
 ActiveSheet.Protect "password", True, True
 End Sub 

Let’s work with the set-by-step code of lines:

Step 1: Open the VBA developer tab either by using
the shortcut keywords Alt +F11 or click on developer window -> visual basic
editor.

Step 2: Visual Basic Editor will open. Next step is
to create a module. Right-clicking on the VBA Project-> Click on Insert->
Click on Module.

VBA ActiveSheet

Step 3: Protect your Excel sheet with the help of
ActiveSheet.Protect method.

VBA ActiveSheet

Output

Step 4: Run the output by clicking the F5 function
key.

Step 5: you will notice you can no more write
anything in the sheet. An alert dialogue box will pop up stating “The cell or
chart you’re trying to change in on a protected sheet. To make a change,
unprotect the sheet. You might be requested to enter a password”

VBA ActiveSheet

To Unprotect the Sheet

To again access/ write or format the sheet you must
unprotect the sheet. To unprotect the Excel sheet, use the ActiveSheet. Unprotect
method.

Code:

Sub ActiveSheet_UnProtectProperty()
 'protect method is used to secure the
 'ActiveSheet with password
 ActiveSheet.Protect "password", True, True
 'unprotecting the sheet
 ActiveSheet.Unprotect "password"
 End Sub 

Now your sheet has been unprotected.

ActiveSheet Clear Method

The ActiveSheet.Clear method is used to clear off all the
content of the cells in the active cells.

Code:

Sub ActiveSheet_ClearProperty()
 'to clear the content of all the cells
 'in the Activesheet with the help of Clear method
 ActiveSheet.Cells.Clear
 End Sub 

VBA ActiveSheet

Output

Before the Clear method

VBA ActiveSheet

After the Clear method: All the content would be erased.

VBA ActiveSheet

Activate another sheet as ActiveSheet

We can active any random sheet as an ActiveSheet. For this,
the ‘.Activate’ method is used.

Code:

Sub ActiveSheet_ActivateSheet()
 'activating Sheet2
 Sheet2.Activate
 'inserting value in cell B2
 ActiveSheet.Cells(2, 2) = "Hello ActiveSheet"
 End Sub 

VBA ActiveSheet

Output

You will notice that in Sheet2, at cell address B2, “Hello
ActiveSheet” value has been entered.

VBA ActiveSheet

Today we are going to learn about VBA Worksheets. We will cover all the nuisances e.g. VBA Activesheet and how it compares to regular Worksheets, how to Select Worksheets, how to Activate Worksheets, Selecting vs Activating Worksheets… and everything else you need to know about the VBA Worksheet in general.

ThisWorkbook vs ActiveWorkbook

Some Excel Worksheets Some Excel WorksheetsLets start with the basics. Before we start I want to stress and remind the difference between ActiveWorkbooks and ThisWorksbooks. In short:

  • ThisWorkbook – refers to the Workbook in which the VBA macro is running
  • ActiveWorkbook – refers to the Workbook which is in the topmost Excel Window

It is extra important to understand this difference and I encourage you to read my post on this topic first.

The Excel VBA Object Hierarchy

Excel vba object hierarchySecondly it makes sense to remind the Excel Object hierarchy.

At the top, at the root we have our Excel Application. The Excel Application represents the entire Excel process. Further down the tree we have our Workbooks. Each Application contains a collection of Workbooks. Looking into a single Workbook we will notice it contains a collection of Worksheets. Worksheets on the other hand as you know can define Ranges (not the same a single cells). Using a Range we can access its cells Values or Formulas.

Accessing VBA Worksheets

Now that we have that behind us lets explore the different ways in which we can access Worksheets in VBA:

ActiveWorkbook VBA Worksheets

The Sheets and Worksheets collections

Sheets within the ActiveWorkbook:

Dim ws as Worksheet, wsCollection as Sheets
Set wsCollection = Sheets 'Get entire collection of Worksheets
Set ws = Sheets(1) 'Get first Worksheet in ActiveWorkbook
Set ws = Sheets("Sheet1") 'Get Worksheet named "Sheet1" in ActiveWorkbook

Similarly we can use Worksheets instead of Sheets.

Dim ws as Worksheet, wsCollection as Sheets
Set wsCollection = Worksheets 'Get entire collection of Worksheets
Set ws = Worksheets(1) 'Get first Worksheet in ActiveWorkbook
Set ws = Worksheets("Sheet1") 'Get Worksheet named "Sheet1" in ActiveWorkbook

ThisWorkbook VBA Worksheets

The Sheets and Worksheets collections

Sheets within the ThisWorkbook:

Dim ws as Worksheet, wsCollection as Sheets
Set wsCollection = Sheets 'Get entire collection of Worksheets
Set ws = ThisWorkbook.Sheets(1) 'Get first Worksheet in ThisWorkbook
Set ws = ThisWorkbook.Sheets("Sheet1") 'Get Worksheet named "Sheet1" in ThisWorkbook

Similarly we can use Worksheets instead of Sheets.

Dim ws as Worksheet, wsCollection as Sheets
Set wsCollection = Worksheets 'Get entire collection of Worksheets
Set ws = ThisWorkbook.Worksheets(1) 'Get first Worksheet in ActiveWorkbook
Set ws = ThisWorkbook.Worksheets("Sheet1") 'Get Worksheet named "Sheet1" in ThisWorkbook

Worksheet VBA Name vs Excel Name

Worksheet VBA Name vs Excel Name When speaking about Worksheets in ThisWorkbook, the VBA Name of a Worksheet is not the same as the Excel Name of a Worksheet. Let us understand this different. On the right we have a screen from an example Workbook. The VBAName string is the VBA Name of our Worksheet, on the other hand the Excel Name string is our Excel Name. You can use both names to refer to the same Worksheet but in different ways.

Using the VBA Name of a Worksheet

Worksheet VBA Name Worksheet VBA NameWe can refer to a VBA Worksheet by its VBA Name directly – just by typing it. This is very convenient and a good practice. That is because the VBA Name can’t be changed by a user by mistake from the level of Excel (not the VBE). Hence whatever name the user give from the Workbook level to your Worksheet – its VBA Name stays the same.

Using the Excel Name of a Worksheet

Referring to an Excel Worksheet from VBA is not a recommended practice. Below I am referring to the Worksheet I named Excel Name in my example above.

Dim ws as Worksheet

Set ws = Worksheets("Excel Name") 'Get Worksheet named "Sheet1" in ActiveWorkbook

Not what you notice is that compared to acquiring the Worksheet by its VBA Name, when using the defaults Worksheets or Sheets object you land with the said Worsheet, but from the ActiveWorkbook. Usually this doesn’t do much of a difference. But I am highlighting that this is simply another place to make a common mistake. See both versions below:

Dim ws as Worksheet

'---Sheet by Excel Name in ActiveWorkbook---
Set ws = Worksheets("Excel Name") 'Get Worksheet named "Sheet1" in ActiveWorkbook
Set ws = ActiveWorkbook.Worksheets("Excel Name") 'Get Worksheet named "Sheet1" in ActiveWorkbook

'---Sheet by Excel Name in ThisWorkbook---
Set ws = ThisWorkbook.Worksheets("Excel Name") 'Get Worksheet named "Sheet1" in ActiveWorkbook

As with Active vs ThisWorkbook you need to first understand the difference between Selecting a Worksheet and Activating it.

Selected vs Activated Worksheet, the differences:

  • Selected Worksheet – one or more Worksheets that have been selected within an Excel Window. Each Workbook has its own set of Selected Worksheets
  • ActiveWorksheet – the current Worksheet you are viewing and working in. The only top-most Worksheet in all Application Workbooks

From the definition above you see that there can be more than 1 Selected Worksheet, while only 1 ActiveSheet. In fact both are totally different things. Lets explore this in some examples:

Example 1: Explaining ActiveSheet

vba worksheets exampleLet us say we have 2 Workbooks open. One is Book1.xlsm and there other is Book2.xlsm.

Lets open VBE in Book1.xlsm. We will add the following piece of code:

Sub TestActiveSheet()
 MsgBox ActiveSheet.Name
End Sub

Now lets activate Book2.xlsm. Rename any Worksheet e.g. to MyActiveWorksheet. Next go to the Developer ribbon select Macros and run Books1.xlsm!TestActiveSheet. What happened? You probably got something like this:
vba activesheet
Although you ran a macro from Book1.xlsm, VBA considers always the top-most worksheet as the ActiveSheet.

Example 2: Explaining Selected vs ActiveSheet

Let us consider the same example. Open Book1.xlsm and add the following code to the VBE:

Sub SelectedVSActive()
  Dim res As String, ws As Worksheet
  res = "Selected sheets:" & vbNewLine
  For Each ws In ActiveWindow.SelectedSheets
    res = res & ws.Name & vbNewLine
  Next ws
  MsgBox res & vbNewLine & "ActiveSheet:" & vbNewLine & ActiveSheet.Name
End Sub

Now do the following:

  • Activate workbook Book2.xlsm
  • Select a number of Worksheets (at least 2)
  • Run Book1.xlsm!SelectedVSActive macro

What happens? You should get something like this:
vba activesheet vs selected
You see that:

  • Only the top-most Worksheet is considered as the ActiveSheet
  • The ActiveSheet is ALWAYS considered as a Selected Worksheet within the ActiveWindow (this last part is important)

What happens if you change ActiveWindow to e.g. Windows(2)? You will see a different set of Selected Worksheets. Why? Because all Workbooks have Selected Worksheets. Hope you see the difference.

Activating VBA Worksheets

Activating Worksheet is easy in VBA. You do it using the Activate property of Worksheets. How to activate any Worksheet using VBA?

Dim ws as Worksheet
'...Set ws to some Worksheet
ws.Activate

Activate Worksheet examples

A few examples below:

Sheets(1).Activate 'Activate first Worksheet in ActiveWorkbook
Sheet1.Activate 'Activate Sheet1 in ThisWorkbook
Worksheets("MyNamedWorksheet").Activate 'Activate Excel named Worksheet in ActiveWorkbook

Selecting VBA Worksheets

Selecting Worksheets is a little more difficult as we may want to select a single Worksheet or more.

Selecting a single VBA Worksheet

Selecting a single VBA Worksheet is simple. Just use the Select property of a Worksheet.

Dim ws as Worksheet
'...Set ws to some Worksheet
ws.Select

Selecting a single Worksheet examples

A few examples below:

Sheets(1).Select 'Select first Worksheet in ActiveWorkbook
Sheet1.Select 'Select Sheet1 in ThisWorkbook
Worksheets("MyNamedWorksheet").Select 'Select Excel named Worksheet in ActiveWorkbook

Selecting multiple VBA Worksheets

Selecting more than 1 Worksheet is a little more complex as we need to leverage the VBA Array function:

Sheets(Array(1, 2)).Select 'Select first and second Worksheet in ActiveWorkbook
Sheets(Array("Named1", "Named2")).Select 'Select 2 named Worksheets in ActiveWorkbook

This is not the most elegant way of doing it. Fortunately the Select function has an argument called Replace. Setting it to false will mean that the previously selected is not to be deselected. Thus we can extend our selections like this:

Sheets(1).Select 
Call Sheets(2).Select(False)
Call Sheets(3).Select(False)

This will select the first three Worksheets in our ActiveWorkbook.

Deleting VBA Worksheets

To delete a VBA Worksheet we need to turn off the Application.DisplayAlerts

Application.DisplayAlerts = False
Sheets(1).Delete
Application.DisplayAlerts = True

You can delete multiple Worksheets in a similar fashion as how you can do a multiple Worksheet Select:

Application.DisplayAlerts = False
Sheets(Array(1, 2)).Delete
Application.DisplayAlerts = True

Copying VBA Worksheets

You can copy Worksheets within a Workbook or from other open Workbooks.

'Copy Sheet1 and paste before Sheet2
Worksheets("Sheet1").Copy Before:=Sheets("Sheet2")

'Copy Sheet1 and paste before Sheet2 in Workbook Book1.xlsm
Worksheets("Sheet1").Copy Before:=Workbooks("Book1.xlsm").Sheets("Sheet2")

Moving VBA Worksheets

You can move Worksheets within a Workbook or from other open Workbooks.

'Move Sheet1 and paste before Sheet2
Worksheets("Sheet1").Move Before:=Sheets("Sheet2")

'Move Sheet1 and paste before Sheet2 in Workbook Book1.xlsm
Worksheets("Sheet1").Move Before:=Workbooks("Book1.xlsm").Sheets("Sheet2")

Other VBA Worksheets properties

Below are other VBA Worksheet properties worth mentioning:

Worksheet propertyDescriptionExampleCalculateCalculates all dirty formulas on the current Worksheet

Dim ws as Worksheet
'...Set ws
ws.Calculate

NameGet or set the Excel Name of the Worksheet

Dim ws as Worksheet
'...Set ws
Debug.Print ws.Name 'Print Excel Name of Worksheet
ws.Name = "New name" 'Set new name for Worksheet

Visible

Display, Hide or make Worksheet VeryHidden. Possible values:

  • xlSheetVisible
  • xlSheetVeryHidden
  • xlSheetHidden
Dim ws as Worksheet
'...Set ws
ws.Visible = xlSheetHidden 'Make ws Worksheet Hidden

To learn more read Unhide sheets in Excel / Unhide all Sheets in Excel using VBA.

The rewards for mastering Microsoft Excel are numerous, though the first steps may be intimidating. Some may get lost in the spreadsheet jargon and may end up more confused that when they first started. Let’s take a look at some of the most common terminology you’ll come across as an Excel user.

Microsoft Excel terminology

  • Workbook — The workbook refers to an Excel spreadsheet file. The workbook houses all of the data that you have entered and allows you to sort or calculate the results. A workbook that is available to be viewed and edited by multiple users on a network is known as a Shared Workbook.
  • Worksheet — Within the workbook is where you’ll find documents called worksheets. Also known as spreadsheets, you can have multiple worksheets nestled in a workbook. Tabs at the bottom of the of the screen will indicate which of your worksheets you are currently working on. This is also known as an active worksheet or active sheet.
  • Cell — A cell is a rectangle or block housed in a worksheet. Any data that you want to enter into your worksheet must be placed in a cell. Cells can be color coded, display text, numbers and the results of calculations, based on what you want to accomplish. An Active Cell is one that is currently opened for editing.
  • Columns and Rows — Columns and Rows refer to how your cells are aligned. Columns are aligned vertically while rows are aligned horizontally.
  • Column and Row headings — These headings are the lettered and numbered gray areas found just outside of columns and rows. Clicking on a heading will select the entire row or column. You can also alter the row height or column width using the headings.
  • Workspace — Much like worksheets in a workbook, a workspace allows you to open numerous files simultaneously.
  • Ribbon — Above the workbook is a section of command tabs called the Ribbon. A multitude of options are found behind each tab of the ribbon
  • Cell Reference — A cell reference is a set of coordinates that identifies a specific cell. It’s a combination of letters and numbers. A5, for example, would point to the cell located where column A and row 5 intersect.
  • Cell Range — A Cell range is a collection of cells that have been identified as a group based on a variety of criteria. By using a colon (:) between cell references, Excel can determine the range, also known as an array. A range in a row, for example, could look like A1:C1, telling the formula to look at the cells in a row between A1 and C1, while B4:D9 would tell the formula to look at all cells in a box bounded by columns B and D and rows 4 and 9. A 3-D reference refers to a range that encompasses more than one worksheet in the same workbook.
  • Merged Cell — When two or more cells are combined, it’s become what is known as a merged cell.
  • Template — A template is a formatted workbook or worksheet designed to help users fulfill a specific need in Excel. Examples of this include stock analysis, process map, and calendar.
  • Operator — Operators are symbols or signs that indicate which calculation must be made in an expression. Operators do not necessarily refer to simple mathematical types; comparison, text concatenation or reference operators also exist.
  • Formula — A sequence inside a cell that is used to produce a value. It must begin with an equal (=) sign. This could be a mathematical equation, cell references, functions or operator. A formula is also known as an expression.
  • Formula Bar — Nestled between the ribbon and workbook, the Formula Bar will display the contents of an active cell. In the case of formulas, the formula bar will display all components of the formula.
  • Function — Functions are formulas that are pre-built into Excel. They are designed to help simplify potentially complex formulas in a worksheet.
  • Error Code — Error Codes appear if Excel finds a problem with a provided formula.
  • Cell Formatting — This is the act of changing the in which cell data is displayed in the spreadsheet. When you format cells, only the visual appearance of the cells is changed; the value within the cells remain constant.
  • Conditional Formatting — Formatting is applied only when the cell meets determined criteria such as duplicate values or values above or below a threshold.
  • Filter — Filters are rules that you can employ to decide which rows in a worksheet to display. These filters can use data such as conditions or values.
  • Freeze Panes — Freezing Panes allows you to select specific columns and/or rows to remain visible on the worksheet, even if you are scrolling, such as header cells that label a column.
  • AutoFill — This enables you to effortless copy data to more than one cell.
  • AutoSum — This feature will add up the numbers you have entered in your sheet and displays the total in a cell of your choosing.
  • AutoFormat — This is an automated format application to cells that match pre-determined criteria. This could be as simple as font alignment and size.
  • Data Validation — This feature helps to prevent incorrect data from being entered into your worksheet. This most commonly used to create drop-down lists for common terms. Data validation promotes consistency and accuracy in the data to be entered.
  • Pivot Table — This is a data summarization tool most commonly used to sort, average to sum up data automatically. The information is pulled from one table while the results are displayed in another. Pivot Tables makes it easy to retrieve specific information from a large source of data.
  • Pivot Chart — This type of chart provides a visual aid for pivot tables. By providing graphical representations of the pivot table data, the user can provide a level of interactivity with the data.
  • Pivot Area — The pivot area is a point on the worksheet where you would drag a Pivot Table field in order to reorganize how a report is displayed.
  • Source Data — This is the information used to create your pivot table. It can either exist within the worksheet or from and an external database.
  • Values Area — In a pivot table, Value areas are identified as the cells that contain the summary information.
  • Item — These are sub-categories of fields in your pivot table. If you have a field that is marked State, the items could be Alabama, Alaska and so on.

Wrapping up

While they are so many other Microsoft Excel terms to cover, the above list will get you on the right track to becoming a table titan. Which terms did you stumble over when you first started using Excel? Are there any other terms that you would suggest for this list? Let us know!

  • Microsoft Office 101: Help, how-tos and tutorials

All the latest news, reviews, and guides for Windows and Xbox diehards.

Like this post? Please share to your friends:
  • What is a 6 word memoir
  • What is a 300 word essay
  • What is a 250 word paper
  • What is a 25 cent word
  • What is 4 pics one word answers