EDUCBA

EDUCBA

MENUMENU
  • Blog
  • Free Courses
  • All Courses
  • All in One Bundle
  • Login
Home VBA VBA Resources VBA Object functions VBA Me

VBA Me

By Ashwani JaiswalAshwani Jaiswal

VBA Me

Excel VBA Me Function

Just by seeing the name VBA Me, people must be wondering what kind of thing is it in VBA called VBA Me? This came to my mind as well when I heard this first time. VBA has an object called ME which is used in place of parent objects. This seems some typical function with complex syntax. But trust me, the syntax of VBA Me might have seen and used as well. Although, VBA Me is used in advanced limit and is not seen in regular commands.

I know, by reading so far, people still may have the question, What is VBA Me? Let’s understand this on a very ground level language. Consider yourself in this case. We all have been given different kind of nicknames since our childhood which can be 2 or more. But all have one official and real name by which we are called by the rest of the world. By which, we introduce us to the rest of the people. So, that real name will be ME in VBA Me object which can be used by replacing similar other identities. This example can be understood in the opposite manner as well.

Watch our Demo Courses and Videos

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

Frankly, VBA Me doesn’t have any defined syntax. This is used as a replacement for parent objects.

How to Use Excel VBA Me Function?

Below are the different examples to use Me Function in Excel VBA.

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

VBA Me – Example #1

VBA ME can be implemented in Module and Sheet both. But we again need to know when should we use what. We can use VBA Me anywhere. It can be used in Class or Module. And Class has 2 modules i.e. Module with User Interface and Module without User Interface. Here, we will see the Module with User Interface. As said, we will execute this into a Module.

Below are the different steps to use VBA Me function.

Step 1: Insert a new module in Visual Basic Editor (VBE). Click on Insert tab > select Module.

VBA Me Example 1-1

Step 2: Write subprocedure for VBA ME as shown below.

Code:

Sub VBA_Me()

End Sub

VBA Me Example 1-2

Step 3: Select Worksheet first. Here, we will be selecting the worksheet which is named as Sheet1.

Code:

Sub VBA_Me()

Worksheets("Sheet1")

End Sub

VBA Me Example 1-3

Step 4: Now select the range cell where we will be seeing the output value. Let that cell be B2 and the value be “VBA Me” as shown below.

Code:

Sub VBA_Me()

Worksheets("Sheet1").Range("B2").Value = "VBA Me"

End Sub

VBA Me Example 1-4

Step 5: Now run the code by pressing the F5 key or by clicking on Play Button. We will see the value is printed in cell B2.

VBA Me Example 1-5

Here, the ME Object will be the name of Sheet which we have selected with the help of Worksheets function. So now we will replace that with ME. But again this won’t work under Module.

Step 6: Go to the sheet which we have selected, i.e. Sheet1.

VBA Me Example 1-6

Step 7: And place the same code as we have seen in Module and replace worksheet function with ME as discussed. Here, for change, we have selected the Range as A2.

Code:

Sub VBA_Me()

Me.Range("A2").Value = "VBA Me"

End Sub

VBA Me Example 1-7

Step 8: Again run the code by pressing the F5 key or by clicking on Play Button.

VBA Me Example 1-8

We will see, VBA ME has returned the text value in cell A2 as well. This is how we can interchange parent object with VBA ME.

VBA Me – Example #2

Now the same VBA ME we will see in User Form. For this, follow the below steps:

Step 1: Open a User Form from Insert menu tab as shown below.

Select UserForm

This will look like this.

User Form with ToolBox

Step 2: In this toolbox select TextBox.

Select TextBox

Step 3: Drag this TextBox on the user form.

Drag this TextBox

Here we are selecting Text box so that we would see the output what we will feed in.

Step 4: Double click on the created text box which we will direct us to edit code mode.

Code:

Option Explicit

Private Sub TextBox1_Change()

End Sub

VBA Me Example 2-5

Step 5: Write the code to select the User Form and Text box which we have created.

Code:

Option Explicit

Private Sub TextBox1_Change()

UserForm1.TextBox1.Value

End Sub

Select the User Form and Text box

Step 6: Now select the text which you want to see in the Text box of User Form. Let that text be “Testing Ok!”.

Code:

Option Explicit

Private Sub TextBox1_Change()

UserForm1.TextBox1.Value = "Testing Ok!"

End Sub

Select the text

Step 7: Now run the code by pressing the F5 key or by clicking on Play Button. We will get a User Form with a Text box in it as shown below. Now if we try to enter anything in that text box, we will see the output message we have set just above.

VBA Me Example 2-8

Here, our ME object will be the name of User Form which is the parent object.

Step 8: So we can replace that with ME to execute VBA ME.

Code:

Option Explicit

Private Sub TextBox1_Change()

Me.TextBox1.Value = "Testing Ok!"

End Sub

VBA Me Example 2-9

Step 9: Again run the code.

VBA Me Example 2-10

Step 10: And try to type anything in the Text box. We will see the same output message in the text box which we have received before.

VBA Me Example 2-11

This is how we can implement VBA ME anywhere by replacing Parent object with ME.

VBA Me – Example #3

There is another simple example to see how VBA Me works. We have created a sheet and named it as Test.

Step 1: Open that sheet in VBA and write the code where we will the name the newly created sheet in the message box.

Code:

Sub VBA_Me2()

MsgBox Sheet2.Name

End Sub

Use MsgBox

Step 2: Now run the code. We will get the name of sheet as Test.

VBA Me Example 3-2

Step 3: Here, Sheet2 has become our object which can be replaced. So, we can replace with ME as shown below.

Code:

Sub VBA_Me2()

MsgBox Me.Name

End Sub

VBA Me Example 3-3

Step 4: And the run the code again. We will see, the name of Sheet Test will be seen in message box.

VBA Me Example 3-4

Pros & Cons of Excel VBA Me

  • It seems complex but it is very easy to implement.
  • We can replace any object with VBA Me.
  • This also helps in reducing the size of code by removing unwanted, mistakable object functions.
  • ME also provides the reference to select a specific instance of Class of the same code.
  • It cannot be implemented in Module.

Things to Remember

  • We need to replace the same object function of parent object which is there in the same Sheet or User Form of the code.
  • It automatically becomes available to every subcategory in the same Class or Form.
  • VBA Me can be used with any type of code where we see the replacement of the parent object.
  • VBA Me can directly be used where we can just use Debug Print or message box where instead of selecting the debugging function or variable, we can replace that with VBA ME.

Recommended Articles

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

  1. VBA DoEvents
  2. VBA Format Number
  3. VBA GetObject
  4. VBA With
All in One Excel VBA Bundle
500+ Hours of HD Videos
15 Learning Paths
120+ Courses
Verifiable Certificate of Completion
Lifetime Access
Financial Analyst Masters Training Program
1000+ Hours of HD Videos
43 Learning Paths
250+ Courses
Verifiable Certificate of Completion
Lifetime Access
All in One Data Science Bundle
1500+ Hour of HD Videos
80 Learning Paths
360+ Courses
Verifiable Certificate of Completion
Lifetime Access
All in One Software Development Bundle
3000+ Hours of HD Videos
149 Learning Paths
600+ Courses
Verifiable Certificate of Completion
Lifetime Access
Primary Sidebar
Financial Analyst Masters Training Program1000+ Hours of HD Videos | 43 Learning Paths | 250+ Courses | Verifiable Certificate of Completion | Lifetime Access
All in One Data Science Bundle1500+ Hour of HD Videos | 80 Learning Paths | 360+ Courses | Verifiable Certificate of Completion | Lifetime Access
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign In
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Excel Charts
  • Excel Tips
  • All Tutorials
Certification Courses
  • All Courses
  • Excel VBA Course - All in One Bundle
  • VBA Course
  • Excel Data Analysis Course
  • Excel for Marketing Course
  • Excel for Finance Course
  • Excel for HR Training

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - 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
Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, 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
Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

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 Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more