Using the previous post as an example, I have modified the statement for you, it should create a new sheet with the data you want when you run the code. You will need to ensure that the ConnString
line points to your file and change the word emailcolumn
to be the name of the column containing your email addresses.
I have assumed that the sheet containing the email addresses is called Sheet1 and the data will go to column A of the new sheet (change the code if needs be):
Sub Excel_QueryTable()
Sheet2.Cells.ClearContents
Dim oCn As ADODB.Connection
Dim oRS As ADODB.Recordset
Dim ConnString As String
Dim SQL As String
Dim qt As QueryTable
ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\t.xlsm;Extended Properties=Excel 8.0;Persist Security Info=False"
Set oCn = New ADODB.Connection
oCn.ConnectionString = ConnString
oCn.Open
SQL = "Select emailcolumn from [Sheet1$] GROUP BY emailcolumn HAVING COUNT(emailcolumn) = 1"
Set oRS = New ADODB.Recordset
oRS.Source = SQL
oRS.ActiveConnection = oCn
oRS.Open
Set qt = Worksheets(2).QueryTables.Add(Connection:=oRS, _
Destination:=Range("A1"))
qt.Refresh
If oRS.State <> adStateClosed Then
oRS.Close
End If
If Not oRS Is Nothing Then Set oRS = Nothing
If Not oCn Is Nothing Then Set oCn = Nothing
End Sub