简体   繁体   English

为什么 Excel 宏将 - 识别为问号?

[英]Why is Excel Macro recognizing − as a question mark?

I am trying to convert a column which has both positive and negative percentages into plain numbers.我正在尝试将具有正负百分比的列转换为纯数字。 For example, -3.5% to 3.5.例如,-3.5% 到 3.5。 There is no problem converting positive percentage to simple numbers.将正百分比转换为简单数字没有问题。 For negative numbers though, result is showing as FALSE.但是,对于负数,结果显示为 FALSE。

I suspect the problem is with this character at the beginning −0.27% and its different from the usual minus (-0.27%).我怀疑问题出在这个字符的开头为 -0.27%,它与通常的减号 (-0.27%) 不同。 How to write a macro to solve this problem?如何编写宏来解决这个问题?

Macro code:宏代码:

ActiveCell.FormulaR1C1 = _
        "=IF(EXACT(LEFT(RC[-4],1),""""),RIGHT(RC[-4],LEN(RC[-4])-1)*-1*100,IF(EXACT(LEFT(RC[-4],1),0),RC[-4]*100))"

Replace with - and then convert it.替换为-然后进行转换。

Try尝试

ActiveCell.FormulaR1C1 = "=ABS(SUBSTITUTE(RC[-4],""−"",""-""))"

在此处输入图像描述

Try尝试

Sub Macro1()
   ActiveCell.Value = "=ABS(RC[-4])*100"
   ActiveCell.NumberFormat = "General"
End Sub

You don't need macro for this you can simply use the Excel's built in function ABS你不需要宏,你可以简单地使用 Excel 内置的 function ABS

Like below像下面

=ABS(A2)*100 =ABS(A2)*100

If you need to automate using VBA then also you can use the ABS function.如果您需要使用 VBA 实现自动化,那么您也可以使用ABS function。

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

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