sinasdf,
Attached is a sample workbook with a button assigned to the following macro:
Sub SeparateDomainsMacro_for_sinasdf()
Dim rngEmail As Range: Set rngEmail = Range("A1", Cells(Rows.Count, "A").End(xlUp))
Dim EmailCell As Range, rngDomain As Range, DomainCell As Range, rngDest As Range
Dim Domain() As String
Dim DomainFound As Boolean
Dim DomainIndex As Long, DomainMax As Long
Application.ScreenUpdating = False
ActiveSheet.UsedRange.Offset(0, 1).Clear
For Each EmailCell In rngEmail
If EmailCell.Row > 1 Then
DomainFound = False
For DomainIndex = 1 To DomainMax
If Domain(DomainIndex) = LCase(Trim(Split(EmailCell.Value, "@")(1))) Then
DomainFound = True
Exit For
End If
Next DomainIndex
If DomainFound = False Then
DomainMax = DomainMax + 1
ReDim Preserve Domain(1 To DomainMax)
Domain(DomainMax) = LCase(Trim(Split(EmailCell.Value, "@")(1)))
rngEmail.AutoFilter 1, "*" & Domain(DomainMax)
Set rngDest = Cells(1, Columns.Count).End(xlToLeft).Offset(0, 1)
Set rngDomain = rngEmail.Offset(1, 0).Resize(rngEmail.Rows.Count - 1, 1).SpecialCells(xlCellTypeVisible)
With rngDest
.Value = Domain(DomainMax)
.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Font.Bold = True
.Font.Size = 12
For Each DomainCell In rngDomain
Cells(Rows.Count, .Column).End(xlUp).Offset(1, 0).Value = DomainCell.Value
Next DomainCell
.EntireColumn.AutoFit
End With
End If
End If
Next EmailCell
rngEmail.AutoFilter
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
Hope that helps,
~tigeravatar
Bookmarks