OK, maybe this:
Option Explicit
Sub sCopyEMailAddresses()
Dim lLR As Long
Dim sHowMany As String
Dim lHowMany As Long
sHowMany = InputBox("Please enter the maximum number of EMail addresses to be copied", _
"Maximum EMail Addresses", _
3)
If Trim(sHowMany) = "" Or sHowMany = "0" Then Exit Sub
lHowMany = sHowMany
Application.ScreenUpdating = False
' using sheet1 ...
With Sheet1 ' original file
' determine how many rows of data (based on column A)
lLR = .Range("A" & .Rows.Count).End(xlUp).Row
' add helper formula in column C
.Range("D2:D" & lLR).Formula = _
"=COUNTIF($A$2:$A2,$A2)"
' filter the records
With .Range("$A$1:$D$" & lLR)
.AutoFilter
.AutoFilter _
Field:=4, _
Criteria1:="<=" & lHowMany
End With
End With
' prepare sheet2 ...
With Sheet2 ' required records
' clear existing data
.Cells.Delete
End With
' back on sheet1 ...
With Sheet1 ' original file
' copy visble cells in columns A and B to sheet2
With .Range("$A$1:$C$" & lLR)
.SpecialCells(xlCellTypeVisible).Copy _
Sheet2.Range("A1")
' switch off the filter
.AutoFilter
' remove the helper column
.Range("D1").EntireColumn.Delete
End With
End With
' and back on sheet2 ...
With Sheet2 ' required records
' make the columns the right width
.Range("A1:C1").EntireColumn.AutoFit
End With
Application.ScreenUpdating = True
End Sub
Regards, TMS
Bookmarks