Solved

Copy and Paste data if Data matched

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

803 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