用于替换所有“.”的 Excel VBA 代码 列中的“,”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26998383/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 05:17:49  来源:igfitidea点击:

Excel VBA code for replacing all "." by "," in a column

excelvba

提问by NT01

I would like to have an excel VBA macro in order to replace all "." (dot) by "," (comma) in a column in one sheet.

我想要一个 excel VBA 宏来替换所有“。” (点)在一张纸的一列中由“,”(逗号)组成。

When I try to do it with the following code, it replaces only if the cell value is ".". But does not replace "." inside cell value (i.e : 1.16 should be turned to 1,16 in column D inside sheet5)

当我尝试使用以下代码执行此操作时,仅当单元格值为“.”时才会替换。但不代替“.” 内部单元格值(即:1.16 应在 sheet5 内的 D 列中变为 1,16)

Sub ReplaceDoTwComma()

Worksheets("Sheet5").Columns("D").Replace _
What:=".", Replacement:=",", _
SearchOrder:=xlByColumns, MatchCase:=True

End Sub

Can someone give me the good code to do this?

有人可以给我好的代码来做到这一点吗?

Thanks in advance...

提前致谢...

回答by cheezsteak

Add the LookAt:=xlPartoption.

添加LookAt:=xlPart选项。

    Worksheets("Sheet5").Columns("D").Replace _
        What:=sought, replacement:=replaced, LookAt:=xlPart

回答by AlexV

you don't need a macro for this, just select the column in question in excel > Crtl + h and in find what put "." and in replace with put "," and hit replace all

您不需要为此使用宏,只需在 excel > Crtl + h 中选择有问题的列,然后找到放置“.”的内容。并替换为放置“,”并点击全部替换