Solved

Copy and Paste data if Data matched

Posted on 2011-02-16
2
774 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 500 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

707 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