我正在努力寻找这个问题的答案......
每个月我都会收到一份包含客户数据的电子表格,这些数据是从某种 CRM 软件中提取的原始数据,而且这些数据一团糟。有些单元格被合并,有些则没有。当您取消合并整个工作表时,您最终会得到一列随机分布在 3 列中并与另一数据混合的数据,即电子邮件地址分布在 3 列中并与邮政编码混合。
我想做的是在 S、T 和 U 列中搜索包含“@”的单元格,并将整个电子邮件地址移动(而不是复制)到同一行的 V 列。
我怎样才能做到这一点?
您可以使用以下公式进入 V1 来实现此目的:
=INDEX(S1:U1,MATCH(TRUE,NOT(ISERROR(SEARCH("@",S1:U1))),0))
公式需要以数组公式形式输入,即按Ctrl-Shift-Enter.
按 Alt+F11 打开 Visual Basic 编辑器,然后单击插入、模块。将其粘贴。或者,只需在此处下载示例文件。然后在 View/Macros 下,这个 movemail() 例程将在那里。运行它。
我接受支票、汇票、贝宝、比特币……:-) j/j Enjoy.
Sub moveemail()
Dim ws As Worksheet
Dim thisCell As Range, nextCell As Range, lookAt As Range
Dim foundAt As String, lookFor As String
Dim lastRow As Long
lookFor = "@"
On Error GoTo Err
'get last populated cell
Set ws = Application.ActiveSheet
With ws
If WorksheetFunction.CountA(Cells) > 0 Then
lastRow = Cells.Find(what:="*", SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
End If
End With
' go cell by cell looking for @ from row 1 to row 10000
Set lookAt = ActiveSheet.Range("S1:U" & lastRow)
Set thisCell = lookAt.Find(what:=lookFor, LookIn:=xlValues, lookAt:=xlPart, SearchDirection:=xlNext)
If Not thisCell Is Nothing Then
Set nextCell = thisCell
Do
Set thisCell = lookAt.FindNext(After:=thisCell)
If Not thisCell Is Nothing Then
foundAt = thisCell.Address
thisCell.Copy Range("V" & thisCell.Row)
thisCell.ClearContents
Else
Exit Do
End If
If thisCell.Address = nextCell.Address Then Exit Do
Loop
Else
'MsgBox SearchString & " not Found"
Exit Sub
End If
Err:
'MsgBox Err.Number
Exit Sub
End Sub