+ Reply to Thread
Results 1 to 7 of 7

[Macro] Compare two columns, if cells differents, copy and delete cell

  1. #1
    Registered User
    Join Date
    11-16-2013
    Location
    France
    MS-Off Ver
    Excel 2007
    Posts
    4

    [Macro] Compare two columns, if cells differents, copy and delete cell

    Good afternoon to all

    I am stuck now for a whole day on creating a macro. I am actually quite a novice regarding VBA and so would really appreciate somebody to give me a hand with this.

    In the attached file, I have three columns, with the third showing discrepancies between the two firsts. Column A and C contain the same values + differences that I must highlight.

    What I am looking to do is that if value in E2 is negative, then copy/paste A2 in I2 and once pasted, delete cell A2 (moving cells up).
    However, if E2 is positive, then copy/paste C2 in J2 and once pasted, delete cell C2 (moving cells up).
    Then only make sure difference formula in E column is correct by copying from original cell E1 (should be done like this I think):

    Range("E1").Select
    Selection.AutoFill Destination:=Columns("E:E")
    Columns("E:E").Select


    Then only do the same for the next lines.

    This should result in having columns A and C completely equals and the different cells shown on the side.

    I hope my explanations are clear enough for you to understand, and I really thank in advance whoever will be able to help me with this.

    Cheers !
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: [Macro] Compare two columns, if cells differents, copy and delete cell

    Quote Originally Posted by Skuz View Post

    What I am looking to do is that if value in E2 is negative, then copy/paste A2 in I2 and once pasted, delete cell A2 (moving cells up).
    delete cell in column A only ? what about the differences ? I think you need delete A2, C2, E2
    If solved remember to mark Thread as solved

  3. #3
    Registered User
    Join Date
    11-16-2013
    Location
    France
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: [Macro] Compare two columns, if cells differents, copy and delete cell

    Thanks for your reply Patel45,

    No actually I really mean cell A only.

    The final result of all this is to have the exact same amounts in both columns A and C but keeping a track of all discrepancies found in every column.
    Now if you take a look at the attachment, E2 is showing a negative value. I then need the macro to copy/paste A2 in I2.
    Then by deleting A2 once pasted, new value in A2 will be the previously A3 value, which means 19 and A2 will now match with C2.

    Next discrepancy will now be shown in line 5 ...

    I hope I'm clear enough now otherwise tell me and I'll try to go further into details.

  4. #4
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: [Macro] Compare two columns, if cells differents, copy and delete cell

    Eliminate manually some cells in column A, what happens ?

    but you can ignore column E and try this code
    Please Login or Register  to view this content.
    Last edited by patel45; 11-16-2013 at 11:19 AM.

  5. #5
    Registered User
    Join Date
    11-16-2013
    Location
    France
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: [Macro] Compare two columns, if cells differents, copy and delete cell

    Example.xlsm

    Thanks Patel45, actually it works now, my only concern is that I have a pop up at the end showing "Error 13 : Incompatibility type" ...

    Although the work is done perfectly, this comes back every time on this sequence : "If Cells(r, 1) - Cells(r, 3) < 0 Then"

    I don't know why ... Attached is a copy of my file if someone can help, I don't understand !

    Thanks

  6. #6
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: [Macro] Compare two columns, if cells differents, copy and delete cell

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    11-16-2013
    Location
    France
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: [Macro] Compare two columns, if cells differents, copy and delete cell

    This time it works perfectly !

    Thank you sincerely Patel45, you rule

    Skuz

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Compare 2 columns, delete cells with no match
    By cmd in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 07-22-2019, 04:52 AM
  2. Compare Two Columns Between Two Worksheets, keep duplicates, delete others, copy new
    By navyav8er in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-14-2012, 03:59 PM
  3. Compare two columns and delete cell in one column if cell next to it is blank
    By jacobhandson in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 12-17-2011, 01:51 PM
  4. Macro to compare multiple columns then delete rows with older dates
    By azurememories in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-23-2011, 05:43 PM
  5. Macro to Compare to Cells and Delete Row
    By randolphoralph in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-24-2008, 04:33 PM

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