0

我正在尝试修复我在 excel 文件中的一堆电子邮件地址。出于某种原因,过去,某些导入程序决定删除一些太长的电子邮件地址,或者以某种方式删除了最后一个字母。这是我们公司的通讯列表。

因此,我的列表中有 100 封以 .ne 或 .co 或 .or 结尾的电子邮件,而不是 .net、.com 或 .org。

我可以使用 Excel 的替换实用程序通过使用 *.ne 的搜索词并选择仅查找完全匹配项来查找损坏的电子邮件。

但是当我表示我想用 *.net 替换找到的项目时,违规者的实际内容将替换为:*.net 而不是电子邮件地址的第一部分。

在这种情况下是否有任何功能或者我可以使用该工具来查找和替换?

问候; 瑞奇

4

6 回答 6

5

I just wrote this macro and tested it on three different email addresses ending in .com, .net, and .org. There is no error-checking and this macro assumes that the email addresses are somewhere within the columns A-Z. It might also try and append an 'm', 't', or 'g' to other data matching the ".co" etc. criteria.

This macro basically scans for cells between A1 and Z30000 (as you mentioned you had a number of addresses) and looks for anything ending in .co .ne or .or. It appends the proper letter to make the address 'complete'. I hope this helps.

Sub Fix_Email()

Dim i As Integer
Dim rngEmail As Range
Set rngEmail = Range("A1:A30000")

For i = 1 To 30000

   'Checks to see if the last 3 characters of a cell's value end in .co, .ne, or .or

    If Right(rngEmail(i).Value, 3) = ".co" Then
        rngEmail(i).Value = rngEmail(i).Value & "m"

    ElseIf Right(rngEmail(i).Value, 3) = ".ne" Then
        rngEmail(i).Value = rngEmail(i).Value & "t"

    ElseIf Right(rngEmail(i).Value, 3) = ".or" Then
        rngEmail(i).Value = rngEmail(i).Value & "g"

    ElseIf Right(rngEmail(i).Value, 2) = ".c" Then 
        rngEmail(i).Value = rngEmail(i).Value & "om" 

    ElseIf Right(rngEmail(i).Value, 2) = ".n" Then 
        rngEmail(i).Value = rngEmail(i).Value & "et"

    ElseIf Right(rngEmail(i).Value, 2) = ".o" Then
        rngEmail(i).Value = rngEmail(i).Value & "rg"

    End If

Next i

End Sub
于 2012-09-18T19:15:23.903 回答
4

只需要遍历单元格并将其拆分为'。' 然后检查变量数组中的最后一个元素是否正确。沿着这些思路。

Sub fixEmails()
ScreenUpdating = False
For Each cell In ActiveSheet.Cells
Dim v As Variant
    If cell.Value <> "" Then
    v = Split(cell.Value, ".")
        If v(UBound(v)) = "ne" Then
        cell.Value = cell.Value + "t"
        Else
            If v(UBound(v)) = "co" Then
                cell.Value = cell.Value + "m"
            Else
                If v(UBound(v)) = "or" Then
                    cell.Value = cell.Value + "g"
                End If
            End If
        End If
    End If
Next

ScreenUpdating = True

End Sub
于 2012-09-18T19:11:02.780 回答
3

我建议添加一个使用公式来显示所需字母的列。然后再使用一列进行连接。然后在原始列上做一个大的“粘贴值”。

=IF(RIGHT(A1,3)=".ne", "t",IF(RIGHT(A1,3)=".co", "m",""))

这给了你这个想法。让 A 列成为您的电子邮件,并且您已经处理了netcom

于 2012-09-18T18:59:06.437 回答
2

Simply when using find and replace in Excel you don't need to use a wildcard. If you run find '.ne' and replace with '.net' and so on for '.co' and '.or' this will work.

However you may face another problem where email addresses may have .ne, .co or .or appearing earlier.

To avoid this I would expand on Smandoli's solution and use the following function alongside your email addresses:

=IF(RIGHT(A1,3)=".ne", A1&"t",IF(RIGHT(A1,3)=".co", A1&"m",IF(RIGHT(A1,3)=".or",A1&"g",A1)))

And then copy and paste values the column afterwards.

于 2012-09-18T21:08:50.567 回答
1

如果 A 是电子邮件地址的列,请提供更多详细信息,您将 B 列设置为:=IF(RIGHT(A3,2)="co","m", IF(RIGHT(A3,2)="ne" , "t", IF(RIGHT(A3,2)="or", "g")))

和列 C 为 =CONCATENATE(A3,B3)

于 2012-09-18T19:13:23.667 回答
0

For this type of task, looping over cells is inherintly quite slow. Using a variant array is much faster

Sub email()
    Dim v As Variant
    Dim rng As Range
    Dim i As Long
    Set rng = Range([A1], [A1].End(xlDown)) ' assuming no blank cells in the list
    v = rng
    For i = 1 To UBound(v, 1)
        Select Case Right(v(i, 1), 3)
            Case ".co"
                v(i, 1) = v(i, 1) & "m"
            Case ".ne"
                v(i, 1) = v(i, 1) & "t"
            Case ".or"
                v(i, 1) = v(i, 1) & "g"
        End Select
    Next
    rng = v
End Sub

executes in < 0.5 sec on ~60,000 rows

于 2012-09-19T07:43:41.053 回答