EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home VBA VBA Resources VBA Object functions VBA Object
 

VBA Object

Ashwani Jaiswal
Article byAshwani Jaiswal
Madhuri Thakur
Reviewed byMadhuri Thakur

VBA Object

VBA Object

In Microsoft Excel, a VBA Object can contain one or more than one object. Such as a single workbook can have one or more than one worksheet. Workbook, Worksheet, Range, and cells are the objects in Excel. Each object has its own properties. And they all have a different method of application. Let say the workbook is the main object which has 2 worksheets in it. Those 2 worksheets will be its child object. One of the sheets has one range, so that sheet will become the main object, and the range will be its child object.

 

 

Workbook

Watch our Demo Courses and Videos

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

How to Use Object in VBA

Let’s see the examples of object in Excel VBA.

You can download this VBA Object Excel Template here – VBA Object Excel Template

Example #1 – VBA Object

It can be written in many ways. Suppose we need to print any text in a cell, so this can be done in various ways. We can directly use the range value to that cell. This direct method is not a part of VBA Object but a process of performing a task that could be done by VBA Object as well. For this:

Step 1: Go to VBA and insert a Module from the Insert menu option as shown below.

Object module

Step 2: Now write the Sub Category of performed function, like VBA Object, in any other name as per your choice, as shown below.

Code:

Sub VBAObject2()

End Sub

VBA Object Example 1.1

Step 3: Now select the range function considering any cell, let’s say cell B3 with Value as shown below.

Code:

Sub VBAObject2()

Range("B3").Value =

End Sub

Excel VBA Object Example 1.2

Step 4: Now add text or word in that range cell as shown below.

Code:

Sub VBAObject2()

Range("B3").Value = "VBA Object"

End Sub

Step 5: Now, compile the code and run it by pressing the play button located below the menu bar.

VBA Object 1

Example #2 – VBA Object

This is the normal way of printing text to any cell. How we will see how the same process can be done when we use VBA Object. For this, we will need another fresh module. And in that,

Step 1: Go to VBA and insert a Module from the Insert menu option as shown below.

 Module 2

Step 2: Write the Sub Category of VBA Object as shown below.

Code:

Sub VBAObject1()

End Sub

 Example 2.1

Step 3: Here, we will see the complete VBA Object from the main to a child category. First, select the currently opened workbook with the help of the command ThisWorkBook with Application, as shown below. This will select the workbook which is actually opened and last selected.

Code:

Sub VBAObject1()

Application.ThisWorkbook

End Sub

Excel VBA Example 2.3

Step 4: Now select the sheet which is currently opened in the workbook, or we can write the name of the worksheet as well. Here, we have written the name of sheet Sheet1 in inverted commas, as shown below.

Code:

Sub VBAObject1()

Application.ThisWorkbook.Sheets ("Sheet1")

End Sub

Example 2.4

Step 5: Now comes the range. Select the range of the cell where we need to print or insert the text. Here we are selecting cell B4, as shown below.

Code:

Sub VBAObject1()

Application.ThisWorkbook.Sheets("Sheet1").Range("B4").Value

End Sub

Example 2.5

Step 6: At last, add the text which we need to see in the select Range cell as shown below.

Code:

Sub VBAObject1()

Application.ThisWorkbook.Sheets("Sheet1").Range("B4").Value = "VBA Object"

End Sub

VBA Example 2.6

Step 7: Now, compile and run the code. We will see cell B4 has the text “VBA Object”.

VBA Object 2

This complete process is called VBA Object. In which we have first selected the main object, i.e. Workbook, which has its child object, i.e. Sheet1, and that has another child object range, i.e. cell B4.

Example #3 – VBA Object

There are many different ways to add text to any cell. One can be with Excel VBA Object, and others can be without it. In these categories, again, there are many ways to do it. Let’s see another way to add VBA Object. For this, we will need a module.

Step 1: In that module, add a subcategory; better make it with sequence number as shown below.

Code:

Sub VBAObject3()

End Sub

VBA Example 3.1

Step 2: Select the worksheet by adding the name of the current worksheet, which is Sheet1, as shown below.

Code:

Sub VBAObject3()

Worksheets("Sheet1").

End Sub

VBA Object Example 3.2

Step 3: Now, add the range of the cell where we want to see the output, as shown below.

Code:

Sub VBAObject3()

Worksheets("Sheet1").Range("A3").Value

End Sub

 Example 3.3

Step 4: At last, give it a value that we can see once we run the code. We are considering the same text as seen in example 1.

Code:

Sub VBAObject3()

Worksheets("Sheet1").Range("A3").Value = "VBA Object"

End Sub

Example 3.4

Step 5: Now run the code. We will see; cell A3 got the text which we wanted to add there, as shown below.

VBA Object 3

In this process, we have directly added the worksheet. So Worksheet will become our Object, and Range will become its child object.

Step 6: There is another way to perform the same task. In the bracket of the worksheet, instead of writing the sheet name, we can write the sequence of the sheet, which is 1, as shown below.

Code:

Sub VBAObject3()

'Worksheets("Sheet1").Range("A3").Value = "VBA Object"
Worksheets(1).Range("B3").Value = "VBA Object"

End Sub

Example 3.5

Step 7: Now run the modified code. We will see cell B3 got the same text VBA Object as cell A3, as shown below.

VBA Object 4

By keeping both the code in line, we can see and compare the changes we made. In another way,

Step 8: Instead of the Worksheet function, if we use the Sheet with sequence and selecting cell C3 as range as shown below.

Code:

Sub VBAObject3()
'Worksheets("Sheet1").Range("A3").Value = "VBA Object"
'Worksheets(1).Range("B3").Value = "VBA Object"
Sheet1.Range("C3").Value = "VBA Object"

End Sub

Example 3.7

Step 9: Now run this code. We will see, again the same text will get added in range cell C3.

VBA Object 5

In all the methods which we have seen in this example, Worksheet is our object, and the range of the cell is child object or Sub-object.

Pros and Cons of  Excel VBA Object

  • We can make as many objects and link them together to sink them.
  • It makes use of Workbook, Sheet, and Range easy.
  • This allows a user to make changes in a specific Workbook, Worksheet or Range.
  • The same process can be performed by a much shorter code with having the same result.

Things to Remember

  • Worksheet and Sheet both have the same use.
  • We can select any worksheet of the same workbook of any number sequence.
  • While writing big lines of code, it is important to form an Object in which the Workbook, Worksheets, and Ranges of different cells are linked.
  • Must save the file in Macro-Enabled Excel format. It allows us to use the code and change the code whenever required.

Recommended Articles

This is a guide to VBA Object. Here we discuss how to use Object in Excel VBA along with practical examples and downloadable excel template. You can also go through our other suggested articles –

  1. VBA IsNumeric
  2. VBA UCASE
  3. VBA Object Required
  4. VBA ByVal

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

Download VBA Object Excel Template

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

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

Forgot Password?

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

🚀 Limited Time Offer! - ENROLL NOW