{"id":242876,"date":"2022-08-10T22:33:19","date_gmt":"2022-08-10T22:33:19","guid":{"rendered":"https:\/\/vmlogger.com\/excel\/?p=242876"},"modified":"2022-08-11T10:25:30","modified_gmt":"2022-08-11T10:25:30","slug":"difference-between-text-value-and-value2-in-excel-vba","status":"publish","type":"post","link":"https:\/\/vmlogger.com\/excel\/2022\/08\/difference-between-text-value-and-value2-in-excel-vba\/","title":{"rendered":"Difference between .Text, .Value and .Value2 in Excel VBA"},"content":{"rendered":"
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<\/span> 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. <\/p>\n 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.<\/span><\/p>\n In simple language, .text() brings the string that is literally visible<\/strong> in a cell.The reason why I say literally visible<\/strong> is because 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 #<\/strong> 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 What is
.Text<\/code><\/strong> property in Excel VBA<\/h1>\n
.Text<\/code><\/strong> returns the formatted value from a cell. Note that
.Text<\/code><\/strong> is a read-only property.<\/strong> It means you can not set it programmatically. Let’s take an example:<\/p>\n
Example:<\/h2>\n
Range(\"B1\").Text<\/code><\/strong> will return the exact number of # keys<\/strong> that are visible on the screen as you can see in the below picture.
\n