Difference between .Text, .Value and .Value2 in Excel VBA

.

One of you raised a question about which property should I be using to get the value of a cell or range – . Text, .Value or .Value2 Most of the time you might have seen all 3 methods being used interchangeably. Rather than answering them in a comment, I thought of writing an article here so that you all can benefit from it and learn something interesting and new.

Before we look into the differences between these 3 – let’s what is common about them. : Well, they all 3 are used to fetch the data from a cell or cell range.

What is .Text property in Excel VBA

In simple language, .text() brings the string that is literally visible in a cell.The reason why I say literally visible is because .Text returns the formatted value from a cell. Note that .Text is a read-only property. It means you can not set it programmatically. Let’s take an example:

Example:

If cell B1 has a long date format but the column width is not adjusted to fit the entire date, what we see is a # hash symbol filled in the cell. Even though if we click on the cell we can see the correct date inside. That means, in such a case, if you are using the following statement in your VBA code Range("B1").Text will return the exact number of # keys that are visible on the screen as you can see in the below picture.

What is returned by .Text

What is returned by .Text

From the above picture it is quite clear what .Text returns in Excel VBA programming.
As I mentioned before, .Text returns the formatted value of a cell, that means, if your cell is formatted for Long Date and it is visible on the screen, then it will return the same long format value.

One of the major drawbacks of .Text property is that it can return all ##### values if a column or row width and height is not adjusted according to the data and cell is displaying ### keys. We have already seen that in the above example.

What is .Value property in Excel VBA

To understand the difference, it is easier, if we take the same example and run our same code, this time with .Value
.Value returns the exact value what is stored in the cell. Unlike .Text property, .Value does not care about the formatting of the cell rather it returns the exact value [Native excel value] that is stored in the cell. You can see that in the below picture:

What is .Value in Excel VBA

What is .Value in Excel VBA

As mentioned before, .Value property returns values stored in Native Excel data types which are: Decimal [double precision], Boolean, Empty, Text and Error.
But in case of Currency and Date formatting, .Value property returns the value in date and currency format after converting its native type Double precision numbers to Data or currency.
The drawback of using .Value in the case of currency is that: In excel currency has a limit of 4 decimal points and therefore, you might lose precision beyond 4 digits after the decimal.
For example: If you have a number 3.68686868, stored in a cell formatted as currency, then .Value will return 3.6869 only. It will round up the value up to 4 digits after decimal before passing it.

What is .Value2 property in Excel VBA

.Value2 returns mostly the same result as .Value except the fact that it does not convert to Currency or Date format too. That means .Value2 is the property that always returns the exact value which is stored in a Native Excel format which is either of the following: Double Precision, Text, Boolean, Error, or Empty.
You can refer the bellow image to see the difference between .Value and .Value2 properties of Excel VBA.

What is Value2 in Excel VBA

What is Value2 in Excel VBA

Bonus tip


Apart from all the above differences, there is one more difference related to their performance. That means how fast do they return the value?

.Text: This is the slowest and the reason is obvious. Before returning the values it looks into formatting of the cell and then converts it accordingly before returning it.

.Value : This is faster than .Text because it converts only in case of formatting is done for currency or date. In all other cases, it returns the value as it is. Therefore, It is little faster than .Text

.Value2 This is the fastest and reason is obvious too. This does not convert any value at all. It returns every cell value in its native data type irrespective of any formatting done on a cell.

Buy a coffee for the author

Adsense

Download FREE Tools and Templates

There are many cool and useful excel tools and templates available to download for free. For most of the tools, you get the entire VBA code base too which you can look into it, play around it, and customize according to your need.

Dynamic Arrays and Spill Functions in Excel: A Beginner’s Guide
Dynamic Arrays and Spill Functions in Excel: A Beginner’s Guide

In today's tutorial, we'll be diving into the exciting world of dynamic arrays and spill functions in Office 365 Excel. These features have revolutionized the way we work with data, providing a more flexible and efficient way to handle arrays. I am going to explain...

How to Declare a Public Variable in VBA
How to Declare a Public Variable in VBA

While programming in VBA sometimes you need to declare a Public Variable that can store the value throughout the program. Use of Public Variable: Let's say you have 4 different Functions in your VBA Code or Module and you have a variable that may or may not be...

How to Copy content from Word using VBA

As many of us want to deal with Microsoft Word Document from Excel Macro/VBA. I am going to write few articles about Word from Excel Macro. This is the first article which opens a Word Document and read the whole content of that Word Document and put it in the Active...

What is Excel Formula?

Excel Formula is one of the best feature in Microsoft Excel, which makes Excel a very very rich application. There are so many useful built-in formulas available in Excel, which makes our work easier in Excel. For all the automated work, Excel Macro is not required. There are so many automated things can be done by using simple formulas in Excel. Formulas are simple text (With a Syntax) which is entered in to the Excel Worksheet Cells. So how computer will recognize whether it is a formula or simple text? Answer is simple.. every formula in Excel starts with Equal Sign (=).

You May Also Like…

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Join and get a FREE! e-Book

Don't miss any articles, tools, tips and tricks, I publish here

You have Successfully Subscribed!

Pin It on Pinterest