1 Then cell.Replace "/", ", " End If 现在我的理解是,如果-6ren">
gpt4 book ai didi

vba - 使用 InStr 确定特定字符的出现次数?

转载 作者:行者123 更新时间:2023-12-04 21:34:52 26 4
gpt4 key购买 nike

我正在做一些数据处理,我使用了代码

If InStr(1, cell.Value, "/") > 1 Then
cell.Replace "/", ", "
End If

现在我的理解是,如果“/”出现多次,它将继续并用“,”替换它。但是,似乎即使只有 1 个“/”,它仍然会执行替换。我不是编码向导,但数学似乎有点缺陷。有谁知道可能是什么问题?

编辑:完整代码
Sub Title()

Application.ScreenUpdating = False
Dim rng As Range
Dim ws As Worksheet
Set ws = ActiveSheet
Dim cell As Range
Set rng = ws.Range(ws.Cells(2, 2), ws.Cells(ws.Rows.Count, 2).End(xlUp))

For Each cell In rng
If InStr(1, cell.Value, " ") > 0 Then
cell.Value = " " & cell.Value & " "
End If
Next cell
rng.Replace " ", " "
'Data Breakdown

'Remove phrases
rng.Replace "at *", ""
rng.Replace "We're *", ""
rng.Replace "We are *", ""
rng.Replace "we're *", ""
rng.Replace "we are *", ""

For Each cell In rng

If (Len(myCell) - Len(Replace(myCell, "/", ""))) > 1 Then
myCell = Replace(myCell.Text, "/", "")
End If


If InStr(1, cell.Value, " Manager of ") > 0 Then
cell.Replace " Manager of ", " Manager, "
End If

Next cell

rng.Replace " IT ", " IT, "
rng.Replace " Manager ", " Manager, "
Application.ScreenUpdating = True
End Sub

最佳答案

如果要替换所有的“/”如果有两个以上,那么:

If (Len(myCell) - Len(Replace(myCell, "/", ""))) > 1 Then
myCell = Replace(myCell.Text, "/", "")
End If

如果您想要其他内容,请具体说明。

关于vba - 使用 InStr 确定特定字符的出现次数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41130065/

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