我不是excel或谷歌搜索的新手,但这种行为令人惊讶/不合逻辑:
这个“bug”(?)在VBA中引起了一些麻烦,因为下面的代码没有将数据转换为预期的结果(文本格式的'数字')而我根本无法将其转换为文本格式:
Selection.Replace What:="74", Replacement:="75"
当我尝试以下任何一种方法时,结果相同:
Selection.Replace What:="74", Replacement:=Format("75", "@")
Selection.Replace What:="74", Replacement:=CStr("75")
Selection.Replace What:="74", Replacement:="75"
Selection.NumberFormat = "@"
只有解决方案才有效:
Selection.Replace What:="74", Replacement:="'75"
但我不希望细胞中有叛逆者......
有没有其他方法可以替换文本,看起来像单元格中的数字 - 通过另一个文本,看起来像数字? 我觉得花一个小时考虑这些基础知识是假的!
编辑: 即使使用命名范围的这种方法也会给出75作为数字(单元格格式为文本):
Selection.Replace What:="74", Replacement:=Range("number_75_in_text_format").Text
答案 0 :(得分:0)
你需要描述你是如何得到这个的。尝试运行其中任何一个:
Sub BugDemo()
With ActiveCell
.Clear
.NumberFormat = "@"
.Value = "101"
.Replace What:="0", Replacement:="7"
End With
End Sub
Sub BugDemo2()
With ActiveCell
.Clear
.NumberFormat = "@"
.Value = "101"
.Replace What:="101", Replacement:="7"
End With
End Sub
更换后,值仍为文字