VBA manage data across tabs.

I have a spreadsheet with two tabs 'source', 'running' and 'completed', the source tab - the tabs have the following columns...


The source tabs data is populated from an externally generated CSV file, what I am looking for is to create a VBA function that copies the data from the source tab to the running tab with the following rules.

1. If a row from the source tab already exists in the running tab update the row with source data (excluding new column).
2. If a row from the source tab does not exist in the running tab add the row and update the 'new' column to 'new'.
3. If a row no longer exists in the source tab then remove it from the running tab and add the id, {timestamp} to the completed tab.

I am completely new to VBA so any sample function would be perfect! Thanks in advance.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Saurabh Singh TeotiaCommented:
Basis of what you are trying to do you can use this code it will do what you are looking for..

Sub getdata()
    Dim ws As Worksheet, ws1 As Worksheet, ws2 As Worksheet
    Dim lr As Long, lr1 As Long, lr2 As Long
    Dim r As Range, cell As Range, r1 As Range, r2 As Range, r3 As Range

    Set ws = Sheets("Source")
    Set ws1 = Sheets("Running")
    Set ws2 = Sheets("Completed")

    lr = ws.Cells(Cells.Rows.Count, "A").End(xlUp).Row
    lr1 = ws1.Cells(Cells.Rows.Count, "A").End(xlUp).Row

    Set r = ws.Range("A2:A" & lr)
    Set r1 = ws1.Range("A2:A" & lr1)

    For Each cell In r
        If Application.WorksheetFunction.CountIf(r1, cell.Value) = 0 Then
            cell.EntireRow.Copy ws1.Range("A" & ws1.Cells(Cells.Rows.Count, "A").End(xlUp).Row + 1)
        End If
    Next cell

    For Each cell In r1
        If Application.WorksheetFunction.CountIf(r, cell.Value) = 0 Then
            If r3 Is Nothing Then
                Set r3 = cell
                Set r3 = Union(cell, r3)
            End If

            lr3 = ws2.Cells(Cells.Rows.Count, "A").End(xlUp).Row + 1
            ws2.Range("A" & lr3).Value = cell.Value
            ws2.Range("b" & lr3).Value = Now()

            ws1.Range("B" & cell.Row & ":F" & cell.Row).Formula = "=VLOOKUP($A" & cell.Row & ",Source!$A$1:$F$" & lr1 & ",COLUMN(),0)"

            ws1.Range("B" & cell.Row & ":F" & cell.Row).Value = ws1.Range("B" & cell.Row & ":F" & cell.Row).Value

        End If
    Next cell

    If Not r3 Is Nothing Then r3.EntireRow.Delete

End Sub

Open in new window

Enclosed is the data file for your reference where i based this sample code on..


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.