+ Reply to Thread
Results 1 to 19 of 19

Compare two workbook

  1. #1
    Registered User
    Join Date
    05-08-2012
    Location
    Budapest
    MS-Off Ver
    2010
    Posts
    33

    Compare two workbook

    Hello

    I need to compare two workbook, but only the first column. and not from the first letter, from the 11. letter. And i don't know how can i do that.

  2. #2
    Registered User
    Join Date
    05-08-2012
    Location
    Budapest
    MS-Off Ver
    2010
    Posts
    33

    Re: Compare two workbook

    the first workbook, from the first letter, and the second workbook from the 11. letter in column A

  3. #3
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Compare two workbook

    Please attach a sample workbook so we understand your requirement.

    To Attach a File:

    1. Click on Go Advanced.
    2. In the frame Attach Files you will see the button Manage Attachments
    3. Click the button.
    4. A new window will open titled Manage Attachments - Excel Forum.
    5. Click the Browse... button to locate your file for uploading.
    6. This will open a new window File Upload.
    7. Once you have located the file to upload click the Open button. This window will close.
    8. You are now back in the Manage Attachments - Excel Forum window.
    9. Click the Upload button and wait until the file has uploaded.
    10. Close the window and then click Submit.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  4. #4
    Registered User
    Join Date
    05-08-2012
    Location
    Budapest
    MS-Off Ver
    2010
    Posts
    33

    Re: Compare two workbook

    i cant upload files, from my workplace

    forexample

    workbook1 - Column A

    world1
    world2
    world3
    world4
    ...etc

    workbook2 - column A

    hello_world1
    1245_world2
    kjgh_world3
    dlle_world4
    .... etc

    do you understand it?

  5. #5
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Compare two workbook

    After comparing, what output do you need?

  6. #6
    Registered User
    Join Date
    05-08-2012
    Location
    Budapest
    MS-Off Ver
    2010
    Posts
    33

    Re: Compare two workbook

    i need to know, how many data equals in the two workbook2 with the workbook1
    there is data in the workbook2, that is not in the workbook1
    (sorry if iam write wrong, iam not so good in english)

  7. #7
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Compare two workbook

    Ok, i understood you .

    One more question - will world1 in workbook1 be in the same row as hello_world1 in workbook2? Will the entries be in the same row so they can be matched or they can be anywhere in the column?

  8. #8
    Registered User
    Join Date
    05-08-2012
    Location
    Budapest
    MS-Off Ver
    2010
    Posts
    33

    Re: Compare two workbook

    no, unfortunately its not in the same row :/

  9. #9
    Registered User
    Join Date
    05-08-2012
    Location
    Budapest
    MS-Off Ver
    2010
    Posts
    33

    Re: Compare two workbook

    can you help me? i have to do this today :/

  10. #10
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Compare two workbook

    Try this code
    Please Login or Register  to view this content.
    For this example, i have saved the files as workbook1.xlsx and workbook2.xlsm. The macro needs to be saved in the 2nd workbook. The macro assumes that workbook1 is also open at the time of running the macro.

    Copy the Excel VBA code
    Select the 2nd workbook in which you need to store the Excel VBA code
    Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
    Choose Insert | Module
    Where the cursor is flashing, choose Edit | Paste

    To run the Excel VBA code:
    Choose Tools | Macro | Macros
    Select a macro in the list, and click the Run button

    Let me explain to you what it does:
    1. Since the format of both the files is not same, a column is inserted in column A of workbook2. Using formulae such as len, right, find, only the world1, world2, etc part of the text is inserted into column A.

    2. Another column is inserted in column B. Here the number 2 is inserted to show that the data has come from workbook2.

    3. The data from workbook1 is copied in column A below the existing data. In column B, the number 1 is inserted for each row belonging to workbook1.

    4. The data is sorted based on column A.

    5. A condition is applied to the data - If row 1 and row 2 match, then the word "Same" is entered in column D, if not, the word "New" is entered.

    Hope this works for you. Please try it on a copy of your file.

  11. #11
    Registered User
    Join Date
    05-08-2012
    Location
    Budapest
    MS-Off Ver
    2010
    Posts
    33

    Re: Compare two workbook

    i dont know yet exactly how it works, but its thow az exepction to this line

    If .Range("A" & i).Value = .Range("A" & i + 1).Value And .Range("B" & i).Value <> .Range("B" & i + 1).Value Then

    Run time error '13': Type mismatch

    i rewrite only the file name

  12. #12
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Compare two workbook

    What are the values you have in columns A & B? Are they the same as what you posted in this thread?

  13. #13
    Registered User
    Join Date
    05-08-2012
    Location
    Budapest
    MS-Off Ver
    2010
    Posts
    33

    Re: Compare two workbook

    the datas are in two excel workbook, not two worksheet, and in the B, C, D....columns are other datas.

  14. #14
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Compare two workbook

    Yes, it should work with 2 excel workbooks. What do you have in columns B, C & D? There is some data in there that is causing the macro not to work. See if you can attach a sample file, or else it will be tough to troubleshoot the problem.

  15. #15
    Registered User
    Join Date
    05-08-2012
    Location
    Budapest
    MS-Off Ver
    2010
    Posts
    33

    Re: Compare two workbook

    i sad i cant upload files

    in workbook1 in column B-H are numbers
    in workbook2 in column B-D are other numbers

  16. #16
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Compare two workbook

    The macro inserts columns in A & B. So ideally your data in B-D will now move forward to D-F. So the macro should not be posing any problems.

    If its still posing problems, i can have the comparison done in a temp worksheet. What do you suggest?

  17. #17
    Registered User
    Join Date
    05-08-2012
    Location
    Budapest
    MS-Off Ver
    2010
    Posts
    33

    Re: Compare two workbook

    Yes, please, do the comparison in a temp worksheet.
    Thanks

  18. #18
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Compare two workbook

    Try this code which creates a "Temp" sheet and does the calculations.
    Please Login or Register  to view this content.

  19. #19
    Registered User
    Join Date
    05-08-2012
    Location
    Budapest
    MS-Off Ver
    2010
    Posts
    33

    Re: Compare two workbook

    it's still trow an exeption to this line :/

    If .Range("A" & i).Value = .Range("A" & i + 1).Value And .Range("B" & i).Value <> .Range("B" & i + 1).Value Then

    runtime error 13
    Type mismatch

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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