我在一个单元格中存储了多封电子邮件,例如5、6。安排在
xxx@gmail.com,hhh@gmail.com,ishd@gmail.com
如何使用VBA用半冒号分隔它,所以我不必手动进行此操作。
答案 0 :(得分:0)
尝试一下。
Sub SplitAll()
Dim xRg As Range
Dim xRg1 As Range
Dim xCell As Range
Dim I As Long
Dim xAddress As String
Dim xUpdate As Boolean
Dim xRet As Variant
On Error Resume Next
xAddress = Application.ActiveWindow.RangeSelection.Address
Set xRg = Application.InputBox("Please select a range", "Kutools for Excel", xAddress, , , , , 8)
Set xRg = Application.Intersect(xRg, xRg.Worksheet.UsedRange)
If xRg Is Nothing Then Exit Sub
If xRg.Columns.Count > 1 Then
MsgBox "You can't select multiple columns", , "Kutools for Excel"
Exit Sub
End If
Set xRg1 = Application.InputBox("Split to (single cell):", "Kutools for Excel", , , , , , 8)
Set xRg1 = xRg1.Range("A1")
If xRg1 Is Nothing Then Exit Sub
xUpdate = Application.ScreenUpdating
Application.ScreenUpdating = False
For Each xCell In xRg
xRet = Split(xCell.Value, ",")
xRg1.Worksheet.Range(xRg1.Offset(I, 0), xRg1.Offset(I + UBound(xRet, 1), 0)) = Application.WorksheetFunction.Transpose(xRet)
I = I + UBound(xRet, 1) + 1
Next
Application.ScreenUpdating = xUpdate
End Sub
之前:
之后:
答案 1 :(得分:0)
听起来您想用换行符代替逗号。我将留下另一个答案,因为我认为这将对将来某个时候来到这里的其他人有所帮助。使用下面的解决方案来完成您想做的事情(我想这就是您想要的)。
Sub ReplaceComma()
Dim rngCell As Range
For Each rngCell In Selection
rngCell.Value = Replace(rngCell, ",", vbLf)
Next
End Sub