简体   繁体   English

如何使用VBA在Excel中的错误单元格中获取基础值

[英]How to get the underlying value in an error cell in excel using VBA

I have this issue to solve purely by VBA, no manual intervention allowed. 我有这个问题可以完全通过VBA解决,不允许手动干预。

In excel, if one puts a non-numerical string starting with minus sign, eg "-SomeData", the cell will show as "#NAME?". 在excel中,如果放置以减号开头的非数字字符串,例如“ -SomeData”,则单元格将显示为“ #NAME?”。 However, if one selects this cell, in the formula bar it will show "=-SomeData". 但是,如果选择此单元格,则在编辑栏中它将显示“ = -SomeData”。

Now I need to extract "-SomeData" and paste it on another sheet. 现在,我需要提取“ -SomeData”并将其粘贴到另一张纸上。 I tried .value but it returned error, and .text but it returned "#NAME?". 我尝试了.value,但返回了错误,而.text却返回了“ #NAME?”。

I browsed through the entire list for Range object on MSDN without finding a viable solution. 我在MSDN上浏览了Range对象的整个列表,但没有找到可行的解决方案。

Is there a way to do this purely by VBA? 有没有办法完全由VBA做到这一点? Asking because the user of the macro refused to do manual formatting for the error cells. 询问是因为宏用户拒绝对错误单元格进行手动格式化。

Thanks in advance. 提前致谢。

假设错误值在活动单元格中,请执行以下操作:

Worksheets(1).Range("A1") = "'" & Activecell.Formula

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM