首页 > 解决方案 > 运行多个“搜索和替换”

问题描述

我在工作中遇到了一些麻烦。这是一项新工作。

我得到了一个 Excel 表,其中一列中有 +3000 封电子邮件。所有这些电子邮件中都有某种类型的打字错误。

我们制定了大约 30 条规则(搜索和替换),可以帮助我们解决打字错误。

它可能是:

有什么方法可以设置这些规则,以便 Excel 自动运行所有 30 个搜索和替换?

标签: excel

解决方案


修改并尝试:

Option Explicit

Sub Insert()

    Dim LastRow As Long, i As Long
    Dim str As String

    With ThisWorkbook.Worksheets("Sheet1")

        LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

        For i = 1 To LastRow

            str = .Range("A" & i).Value

            If InStr(1, str, "gnail.com") <> 0 Then
                .Range("A" & i).Replace What:="gnail.com", Replacement:="gmail.com"
            ElseIf InStr(1, str, "gmail.co") <> 0 Then
                .Range("A" & i).Replace What:="gmail.co", Replacement:="gmail.com"
            ElseIf InStr(1, str, "autlook.com") <> 0 Then
                .Range("A" & i).Replace What:="autlook.com", Replacement:="outlook.com"
            End If

        Next i

    End With

End Sub

推荐阅读