Copy Data

I need Experts help create macro to copy data from Source sheet to Data sheet. If data available in Column I (Source), copy data of the row (Column A,B,C and I) to Data sheet. The copy process should always take the new row at Data sheet, should not overwritten the old data . Hope Experts could help.

Who is Participating?
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.

Peter KwanAnalyst ProgrammerCommented:
You may add the following code to your macro:

Sub CopyData()
    Dim i As Integer
    Dim r As Integer
    Dim r2 As Integer
    Dim ss As Worksheet
    Dim sd As Worksheet
    Set ss = Sheets("Source")
    Set sd = Sheets("Data")
    r = ss.UsedRange.Rows.Count
    For i = 2 To r
        If ss.Cells(i, 9) <> "" Then
            r2 = sd.UsedRange.Rows.Count + 1
            sd.Cells(r2, 1) = ss.Cells(i, 1)
            sd.Cells(r2, 2) = ss.Cells(i, 2)
            sd.Cells(r2, 3) = ss.Cells(i, 3)
            sd.Cells(r2, 4) = ss.Cells(i, 9)
            sd.Cells(r2, 1).NumberFormat = "yyyy-m-d h:mm AM/PM"
            sd.Cells(r2, 2).NumberFormat = "hh:mm:ss.00"
        End If
    Next i

End Sub

Open in new window

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
Billa7Author Commented:
Hi pkwan,

I have tested, the data was not copied to Data sheet.
Peter KwanAnalyst ProgrammerCommented:
I found that the data is copied to much lower (around row 1,900) of the data sheet due to I used "sd.UsedRange.Rows.count" which sets the last used row in the Data sheet.

If you want to put the data to begin at row 2, you need to delete all the data except the header row (row 1).
Billa7Author Commented:

Thanks a lot for the help.
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.