gpt4 book ai didi

excel - 使用replace和find函数同时查找多个 "dot"值

转载 作者:行者123 更新时间:2023-12-04 22:28:20 26 4
gpt4 key购买 nike

我使用 FIND 和 REPLACE 函数在数字中的选定单元格范围内查找点,并将它们替换为空。

我想实现一个代码来查找多个点并通过仅执行一次此过程来替换它们。例如:

选择:1.169.499,08 --> 所需输出:1169499,08

选择:111.222,08 --> 所需输出:111222,08

我尝试过的代码是:

Sub DEtoFR()
'defining the variable z which stores the German number formatting
'defining the variable x which stories the French number formatting

Dim z as Range, x as Variant
Set z = Selection.SpecialCells(xlCellTypeConstants,xlCellTypeConstants)

'Find Counts the Location of the "." character.
'Replace will look for it and replace "." with "".

For Each x in z
x.Value = Application.WorksheetFunction.Replace(x.Value, Application.WorksheetFunction.Find(".", x.value), 1, "")
Next x

End Sub

最佳答案

这是另一种做事方式,也许你会得到一些有用的东西:
之前:enter image description here
代码:

Sub Test()

Dim RNG As Range, LR As Double
With ActiveWorkbook.Sheets(1)
LR = .Cells(Rows.Count, 1).End(xlUp).Row
Set RNG = .Range(Cells(1, 1), Cells(LR, 1)).SpecialCells(2)
RNG.Replace What:=".", Replacement:="", SearchOrder:=xlByColumns, MatchCase:=True
End With

End Sub
结果: enter image description here

关于excel - 使用replace和find函数同时查找多个 "dot"值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55531568/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com