Solved

EXcel VBA

Posted on 2012-03-13
7
352 Views
Last Modified: 2012-03-13
I have an Excel workbook with two sheets (Master & Subset). I need to copy rows from the Master sheet to the Subset sheet which have a date in a particular field (Column O). The data starts in row 9 and extends to row 1980.

I have tried several methods and have not met with success. Finally I implemented the code below with the intent to copy all the rows from Master to Subset and then filter in Subset for the column above. The effect would be that only the rows with dates in column O would be displayed in the Subset sheet.

My Problem is the filter is excluding the first row in Subset. So i am getting an extra row in my result which most times should have been filtered out.


Sub CopyRange()

Sheets("Master").Select
    Range("A9:P1980").Select
    Selection.Copy

    Sheets("Subset").Select
    Range("A9").Select
    ActiveSheet.Paste
    Sheets("subset").Range("A9:P1980").AutoFilter Field:=15, Criteria1:="<>"

End Sub

How can I make this work? Is there another way to achieve my aim?
0
Comment
Question by:Markwedd
[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
  • 4
  • 3
7 Comments
 
LVL 10

Expert Comment

by:SANTABABY
ID: 37716427
Not sure why you don't want apply the filter on the entire column(in subset sheet)? any partucular reason?
Would you prefer the code to copy only the qualified rows to subset sheet?

Is it possible to atach a sample, hopefully that's answer my questions.

Thanx,
SB
0
 

Author Comment

by:Markwedd
ID: 37716666
I only applied the filter on the partial column to avoid getting portions of the header in the mix.

I am open to any solution which allows me to achieve my aim.

I could only attach a workbook without data.
0
 
LVL 10

Expert Comment

by:SANTABABY
ID: 37716831
Do you need row 1-8 in the subset?
I realize that you have sensitive data in your spreadsheet. Could you please attach a workbook with made up data(just enough to describe the problem)?
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

Author Comment

by:Markwedd
ID: 37717176
ROw 1-8 is the header. Please see attached workbook.
TTLC-Master.xls
0
 
LVL 10

Accepted Solution

by:
SANTABABY earned 500 total points
ID: 37717579
Please try the following CopyRange routine(replace you current code), which will keep your header rows (1-8) intact and filter the subsequent rows. Please let me know if this not what you wanted.

Sub CopyRange()

Sheets("Master").Select
    Range("A9:P1980").Select
    Selection.Copy

    Sheets("Subset").Select
    Sheets("Subset").AutoFilterMode = False
    Range("A9").Select
    ActiveSheet.Paste
    'Sheets("subset").Range("A1:P1980").AutoFilter Field:=15, Criteria1:="<>"
    Sheets("subset").Range("A8:P1980").AutoFilter Field:=15, Criteria1:="<>"

End Sub
0
 

Author Closing Comment

by:Markwedd
ID: 37717639
Thank you SANTABABY! That worked.

Could you tell me what I would have to do to delete the fields with blank instead of just removing them from view.
0
 
LVL 10

Expert Comment

by:SANTABABY
ID: 37717891
Try the following please:

Sub CopyRange()

Sheets("Master").Select
    Range("A9:P1980").Select
    Selection.Copy

    Sheets("Subset").Select
    Sheets("Subset").AutoFilterMode = False
    Range("A10").Select
    ActiveSheet.Paste
    'Sheets("subset").Range("A1:P1980").AutoFilter Field:=15, Criteria1:="<>"
    Range("A9").Clear
    Sheets("subset").Range("A9:P1980").Select
    Selection.AutoFilter Field:=15, Criteria1:="="
    Selection.SpecialCells(xlCellTypeVisible).Select
    Selection.Copy
    Selection.EntireRow.Delete
    Sheets("Subset").AutoFilterMode = False


End Sub
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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

733 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