We have seen different Objects in the previous tutorial, we will see the different examples on Workbook, Sheets, Range and Cell objects in this session.
Objects in Excel VBA - Workbook, Sheets, Range and Cell

Workbook Object in Excel VBA

The following are some example codes on Workbook Object, will help you dealing with various methods and properties of Excel workbook.

How to activate a Workbook

Yo can use Activate method to activate a Workbook as shown below:

Workbooks(“Workbook1.xlsx”).Activate

How to get the path of the Workbook

Yo can use FullName method of a Workbook as shown below:

Workbooks(“Workbook1.xlsx”).Path

How to get the full path (including name) of the Workbook

Yo can use FullName method of a Workbook as shown below:

Workbooks(“Workbook1.xlsx”).FullName

How to change the name of the Workbook

Workbooks(“Workbook1″).Name=”New Name”

Worksheet Object of Workbook in Excel VBA

The following are some example codes on Worksheet Object, will help you to deal with activating and selecting Excel worksheet.

How to Activate a Worksheet

Sheets(“Sheet2”).Activate

How to Select a Worksheet

Sheets(“Sheet2”).Select

How to rename a Worksheet

Sheets(“Sheet2″).Name=”NewSheet”

How to Hide a Worksheet

Sheets(“Sheet2”)..Visible = False

How to UnHide a Worksheet

Sheets(“Sheet2”).Visible = True

Range Object of Worksheet in Excel VBA

The following are some example codes on Range Object, will help you to deal with range colors, selection, etc.

How to Select a Range

Range(“A3”).Select

How to Enter Some Data in a Range

Range(“A3”).value=3000

How to change background color of Range

Range(“A1:E20”).Interior.ColorIndex=5

How to Clear a Range

Range(“A1:E20”).Clear

How to Copy a Range from one sheet to another sheet

Sheets(“Sheet1”).Range(“A1:E20”).Copy Destination:=Sheets(“Sheet2”).Range(“D1”)

Cells Object of Worksheet in Excel VBA

The following are some example codes on Cells Object.

How to Select a Range(“A3”)

Cells(3,1).Select

How to Enter Some Data in a Range(“A3”)

Cells(3,1).value=3000

How to change Font color of a Cell

Cells(3,1).Font.ColorIndex=5

How to Clear all Cells of a worksheet

Sheets(“Sheet1”).Cells.Clear

How to Clear only content not formats of all Cells of a worksheet

Sheets(“Sheet1”).Cells.ClearContents

120+ Professional Project Management Templates!
Save Up to 85% LIMITED TIME OFFER

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.

Browse All Templates
Excel VBA Project Management Templates

All-in-One Pack
120+ Project Management
Premium Templates
View Details

Essential Pack
50+ Project Management
Premium Templates
View Details
50+ Excel
Project Management
Templates Pack
View Details
50+ PowerPoint
Project Management
Templates Pack
View Details
25+ MS Word
Project Management
Templates Pack
View Details
Ultimate Project Management Template
View Details
Ultimate Resource Management Template
View Details
Project Portfolio Management Templates
View Details
By Last Updated: June 17, 2022Categories: Excel VBATags: ,

Share This Story, Choose Your Platform!

One Comment

  1. Reinaldo Rojas April 4, 2020 at 4:31 PM - Reply

    Excelente work

Leave A Comment