• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Copy top 5 filtered cells to another destination

dhruvsodani

New Member
I have a 20000 rows of data on which I have applied filter. Now I want to copy only top 5 rows using Macros (of course)
 
How this? Possibly not the fastest way, but it works.

[pre]
Code:
Sub Top5Records()
Dim CopyRange As Range
Dim RecordCount As Integer
i = 6

'Assuming filter as already been applied
Application.ScreenUpdating = False
'Keep incremeting until we have five records
Do Until RecordCount = 5
RecordCount = Range("a2", Cells(i, "A")).SpecialCells(xlCellTypeVisible).Count
i = i + 1
Loop

'Top five records are copied
Range("2:" & i).SpecialCells(xlCellTypeVisible).Copy
Application.ScreenUpdating = True
'What next?

End Sub
[/pre]
 
Back
Top