+ Reply to Thread
Results 1 to 3 of 3

How to compare and copy data from one xls-file to another xls-file

Hybrid View

  1. #1
    Registered User
    Join Date
    11-19-2008
    Location
    Denmark
    Posts
    2

    How to compare and copy data from one xls-file to another xls-file

    I've got a problem with some data I want to compare and copy, from one xls-file to another xls-file. That I hope someone can help me with.

    I've made a macro, that can copy the data I want copied. But now there's more then one row to copy, and it's not sure that all the data need's to be copied. So the macro must be able to compare the data, and if the data is the same in the given row, it should not copy that the data, but continue to the next row. Until al the rows a compared.


    Here is det code I've made. (This just copies the data.):

    Sub Bank1Slot1()
    '
    ' Bank1Slot1 Macro
    ' Macro recorded 17-11-2008 by Godfasher
    '
    ' Keyboard Shortcut: Ctrl+a
    '
        Workbooks.Open Filename:= _
            "C:\Bank1.xls"
        Sheets("Slot1").Select
        Rows("6:6").Select
        Selection.Insert Shift:=xlDown
        Windows("PVE LAB TEST OVERVIEW.xls").Activate
        Range("D5:H5").Select
        Selection.Copy
        Windows("Bank1.xls").Activate
        Range("B6").Select
        ActiveSheet.Paste
        Range("H6").Select
        Application.CutCopyMode = False
        ActiveCell.FormulaR1C1 = "=RC[-1]-RC[-2]"
        Range("H6").Select
        Selection.NumberFormat = "0"
        Range("C6:G6").Select
        Range("G6").Activate
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlBottom
            .WrapText = False
            .Orientation = 0
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = False
        End With
        Range("B6").Select
        With Selection
            .HorizontalAlignment = xlLeft
            .VerticalAlignment = xlBottom
            .WrapText = False
            .Orientation = 0
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = False
        End With
        Range("A1").Select
        Sheets("Slot1").Select
        Range("A1").Select
        ActiveWorkbook.Save
        ActiveWorkbook.Close
    End Sub
    Looking forward to hear from you.
    /Godfasher
    Last edited by VBA Noob; 11-19-2008 at 08:08 AM. Reason: Added code tags as per forum rules

  2. #2
    Forum Contributor
    Join Date
    02-27-2008
    Posts
    764
    Hi
    Which cells/columns/rows you want to compare with? which cells you want copied if they are not same
    Ravi

  3. #3
    Registered User
    Join Date
    11-19-2008
    Location
    Denmark
    Posts
    2

    Red face

    Hi Ravi

    Describtion for one area:

    1. I want to open 1st.xls, copy the cells D5:H5.
    2. Open 2nd.xls.
    3. Compare the copied cells to the data in cell B6:F6 in Sheet1.
    4a. If the data is the same, I want to go back to 1st.xls.
    4b. If not, insert new row i row 6, paste data and go back to 1st.xls.
    5. Copy cells D6:H6.
    6. Goto the 2nd.xls
    7. Compare the copied cells to the data in cell B6:F6 in Sheet2.
    8a. If the data is the same, I want to go back to 1st.xls.
    8b. If not, insert new row i row 6, paste data and go back to 1st.xls.
    And so on...

    I have to compare/copy data from 15 areas i 1st.xls into 15 files. (2nd.xls, 3rd.xls, 4th.xls ... 16th.xls)
    To store data in the 15 files, from 1st.xls.

    The areas in 1st.xls, is between 4 to 12 rows

    The code from the first post, only copies the data, so I'll get a lot of the same data, in 5 rows if I only update 1 of 6 rows in a area of 6. Thats why I want to compare, the rows...

    Hope it's enough info. If not, just write again.

    /Godfasher
    Last edited by Godfasher; 11-19-2008 at 08:14 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1