What is the difference between .text, .value, and .value2?

后端 未结 6 1960
孤独总比滥情好
孤独总比滥情好 2020-11-22 00:07

What is the difference between .text, .value, and .value2? Such as when should target.text, target.value, and target.value2 be used?

6条回答
  •  长情又很酷
    2020-11-22 00:37

    .Text gives you a string representing what is displayed on the screen for the cell. Using .Text is usually a bad idea because you could get ####

    .Value2 gives you the underlying value of the cell (could be empty, string, error, number (double) or boolean)

    .Value gives you the same as .Value2 except if the cell was formatted as currency or date it gives you a VBA currency (which may truncate decimal places) or VBA date.

    Using .Value or .Text is usually a bad idea because you may not get the real value from the cell, and they are slower than .Value2

    For a more extensive discussion see my Text vs Value vs Value2

提交回复
热议问题