Solved

Copy ten first rows in range omitting hidden rows (VBA)

Posted on 2014-02-11
3
511 Views
Last Modified: 2016-10-24
I have a sheet with filtered and sorted data and I want to copy the first ten visible rows and paste into another range.

How can I omit the rows hidden by filter and still get exactly ten?
0
Comment
Question by:Mamarazzi
3 Comments
 
LVL 48

Accepted Solution

by:
Rgonzo1971 earned 300 total points
ID: 39850164
HI,

You could use this method
Sub Macro()
Limit = 10
Idx = 1
Set myRange = Range("A1:C25").SpecialCells(xlVisible)
For Each myArea In myRange.Areas
    For Each rw In myArea.Rows
        If Idx <= Limit Then
            strFltrdRng = strFltrdRng & rw.Address & ","
            Idx = Idx + 1
        End If
    Next
Next
strFltrdRng = Left(strFltrdRng, Len(strFltrdRng) - 1)
Set myFltrdRange = Range(strFltrdRng)
myFltrdRange.Copy

End Sub

Open in new window

EDIT Renaming vars

Regards
0
 

Author Comment

by:Mamarazzi
ID: 39852727
Perfect, thanks a lot!
0
 

Expert Comment

by:Suresh Arunthathiyar
ID: 41858086
i want to copy first 50 visible rows and paste into another range, i tried to change the limit as 50. However im getting some error 'Method range of Object_Global failed'.

Please assist me with the same
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now