+ Reply to Thread
Results 1 to 10 of 10

Compare similar columns

  1. #1
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Compare similar columns

    Hello everybody
    I have many columns .. There are similar columns in values
    if column A = column B Then Delete column B
    if column A = column C then delete column C
    if column A = column D Then Delte Column D
    and so on till the end of columns (The columns are unknow they are dynamic)

    After that
    if column B = column C Then Delete column C
    if column B = column D Then Delete column D
    and so on till the last column
    After that with Column C and D and so on till the last column

    Thanks advanced

  2. #2
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Compare similar columns

    Is the comparison to be done row by row?
    - Battle without fear gives no glory - Just try

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Compare similar columns

    That sounds straightforward, but may be deceptive in what you really mean by "delete column B". I am assuming you mean clear specific cells?

    To alleviate any weirdness at all and allow us to see exactly what you mean, upload a sample workbook with BEFORE and AFTER sample data sets.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Compare similar columns

    No weirdness No deception..
    If all values in Column A for example = All the values in Column B then Column B to be deleted ..
    The idea is to compare every column with the other columns and delete the other columns if they are identical to the column

  5. #5
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Compare similar columns

    Perhaps try for the active sheet.
    Do a safety record before running the macro
    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Compare similar columns

    Perfect Awesome Solution
    Thank you very much for this perfect and swift reply

  7. #7
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Compare similar columns

    I have an attachment that do the same task ...
    It's perfect in the attachment but when I tried to copy the code and apply it on my workbook I found all columns deleted and there is an error (Object required)
    Here's the code :
    Please Login or Register  to view this content.
    And Here's the attachment which works well .. try to copy the code and apply it to another workbook I got errors
    Attached Files Attached Files

  8. #8
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Compare similar columns

    I want to detect the error cause?

  9. #9
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Compare similar columns

    I'm a bit confused: What about the code sent? Why not to use it?
    There is for me a difficulty when using next statement in a loop,
    Please Login or Register  to view this content.
    index variables (i, j) can be "disturbed", you can loop until column 30 which don't exist anymore.
    we have better to loop from LastCol to 1
    That is the reason I was using a range "RgDel" with the Union statement to delete in one shot all columns.
    In the other hand there is not a comparison of the full column: That was my first question, see item #2
    Last edited by PCI; 12-29-2014 at 07:06 PM.

  10. #10
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Compare similar columns

    Mr. PCI
    your code is perfect and I'm using it .. thanks a lot for this wonderful code

+ 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 two columns for Exact match and Similar matches
    By murtz in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-20-2014, 08:16 AM
  2. Replies: 5
    Last Post: 10-26-2013, 01:03 PM
  3. Compare two columns with a series of text and show which cells are similar.
    By abrig005 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-10-2013, 01:01 PM
  4. Compare columns for similar values
    By uncleslinky in forum Excel General
    Replies: 1
    Last Post: 04-07-2009, 02:08 AM
  5. Compare 2 similar excel worksheets
    By Nadia in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-28-2006, 09:25 AM

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