簡體   English   中英

如果 Excel 2010 中單元格范圍內的單元格包含特定文本,請將整個單元格文本移動到不同的列中

[英]If a cell in range of cells in Excel 2010 contains specific text, move whole cell text into a different column

我正在努力尋找這個問題的答案......

每個月我都會收到一份包含客戶數據的電子表格,這些數據是從某種 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 編輯器,然后單擊插入、模塊。 將其粘貼進去。或者,只需在此處下載示例文件。 然后在視圖/宏下,這個 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM