Solved

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

Posted on 2014-02-11
3
667 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 52

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa‚Ķ

630 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