如果Excel 2010中单元格区域中的单元格包含特定文本,请将整个单元格文本移动到其他列中

时间:2013-02-14 09:43:32

标签: excel full-text-search excel-2010

我正在努力寻找这个问题的答案......

每个月我都会收到一份包含客户数据的电子表格,这些数据是来自某种CRM软件的原始数据,而且数据很乱。有些单元格合并,有些则不合并。当您取消合并整张工作表时,您最终得到的数据是针对一列随机分布在3列中并与其他数据混合,即电子邮件地址分布在3列并与邮政编码混合。

我希望能够做的是在S,T和U列中搜索包含“@”的单元格,并将整个电子邮件地址移动(不复制)到同一行的第V列。

我怎样才能做到这一点?

2 个答案:

答案 0 :(得分:0)

您可以使用以下公式在V1中实现此目的:

=INDEX(S1:U1,MATCH(TRUE,NOT(ISERROR(SEARCH("@",S1:U1))),0))

公式需要作为数组公式输入,即按 Ctrl - Shift - 输入

答案 1 :(得分:0)

按Alt + F11以打开Visual Basic编辑器,然后单击“插入”,“模块”。粘贴它。或者,只需下载示例文件here。然后在View / Macros下,此movemail()例程将在那里。跑吧。

我拿支票,汇票,贝宝,比特币... :-) j / j享受。

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