?
Solved

Copy and Paste data if Data matched

Posted on 2011-02-16
2
Medium Priority
?
776 Views
Last Modified: 2012-06-21
Hi Experts,

I would like to request Experts help to modify the attached script to allow copy data from Filter sheet into Archive sheet if the data at Column D is matched with data at Column G. Data at Column I need to be omitted. Hope Experts will help me to modify the script. I have attached as well the workbook for Experts perusal.



Sub CopyOver()
Dim sheetFilter As Worksheet
Dim sheetArchive As Worksheet
Set sheetFilter = Worksheets("Filter")
Set sheetArchive = Worksheets("Archive")
Dim collectRange As Range, curRange As Range
Set curRange = sheetFilter.Range("A2")
While curRange.Value <> ""
    If curRange.Offset(, 3) = curRange.Offset(, 6) And _
        curRange.Offset(, 6) = curRange.Offset(, 8) Then
        If collectRange Is Nothing Then
            Set collectRange = curRange
        Else
            Set collectRange = Union(collectRange, curRange)
        End If
    End If
    Set curRange = curRange.Offset(1)
Wend
Dim targetRange As Range
Set targetRange = sheetArchive.Range("A" & Rows.Count).End(xlUp)
If targetRange.Value <> "" Then Set targetRange = targetRange.Offset(1)
If Not collectRange Is Nothing Then
    Application.EnableEvents = False
    collectRange.EntireRow.Copy targetRange
    collectRange.EntireRow.Delete
    Sheets("Filter").Range("A2:A65536").SpecialCells(2).EntireRow.Delete
    Application.EnableEvents = True
End If
End Sub

Open in new window

DataArchive.xls
0
Comment
Question by:Cartillo
[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
2 Comments
 
LVL 3

Accepted Solution

by:
imaki06 earned 2000 total points
ID: 34913911
I cannot see the problem. The macro does copy the lines where D and G columns has equal values..

Do you want to modify the macro to not check column I or do not want to copy column I to archive?

If the first is what you want, then just remove checking from lines 9 and 10..
change:
..
 If curRange.Offset(, 3) = curRange.Offset(, 6) And _
        curRange.Offset(, 6) = curRange.Offset(, 8) Then
        If collectRange Is Nothing Then
..
to:
..
 If curRange.Offset(, 3) = curRange.Offset(, 6)  Then
        If collectRange Is Nothing Then
..
0
 

Author Closing Comment

by:Cartillo
ID: 34914015
Thanks for the help
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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

800 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