本文介绍了收到错误的价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  Sub commaToDot()

ActiveWorkbook.Sheets(Oficial)。激活

列(B:B)。选择
Selection.Replace什么:=,,替换:=。,LookAt:= xlPart,_
SearchOrder:= xlByRows,MatchCase:= False,SearchFormat:= False,_
ReplaceFormat:= False

End Sub

正如我在数据中可以看到的那样。它将B列中的所有逗号替换为点。



稍后在我的代码中,我将一些值(已经有COMMAS,现在有DOTS)复制到其他单元格,但是值会显示COMMAS。



为什么?我认为有一些记忆不当行为,但我不知道如何解决它。任何建议?

解决方案

我猜这是国际格式化问题。例如,如果您的Windows区域设置是葡萄牙语,或者使用逗号作为十进制的其他语言,那么您的问题可能与您的VBA例程有关,导致目标单元格将点号解释为数字而不是作为文本字符串。



要强制Excel将粘贴值解释为字符串,可能最简单的方法是在要复制的值之前单引号。这将显示在公式栏中,但不会显示在单元格或任何打印输出中。您也可以将文本格式化为文本格式,但可能不是那么愿意。


At the begin of my macro, I call this macro that changes all commas to dots.

Sub commaToDot()

 ActiveWorkbook.Sheets("Oficial").Activate

 Columns("B:B").Select
     Selection.Replace What:=",", Replacement:=".", LookAt:=xlPart, _
     SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
         ReplaceFormat:=False

End Sub

It works, as I can see in my data. It replaces all commas to dots from the column B.

Later in my code, I copy some of the values (which had COMMAS and now have DOTS) to other cells, but the values appear with COMMAS.

Why? I am thinking there is some memory misbehavior, but I have no idea how to work around it. Any suggestions?

解决方案

My guess this is an International formatting problem. For example, if your Windows Regional Settings are Portuguese, or some other language that is using the comma as a decimal, then your problem likely relates to your VBA routine doing something to cause the destination cell to interpret the "dotted number" as a number and not as a text string.

To force Excel to interpret the "pasted" value as a string, probably the simplest method would be to precede the value to be copied with a single quote mark. This will show up in the formula bar, but not in the cell or any printouts. You could also pre-format the cell as text, but that may not be as desireable.

这篇关于收到错误的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 11:02