+ Reply to Thread
Results 1 to 5 of 5

comparing the column headers, then deleting the entire column iif duplicates occur

  1. #1
    Registered User
    Join Date
    06-10-2011
    Location
    helsinki, finland
    MS-Off Ver
    Excel 2007
    Posts
    15

    comparing the column headers, then deleting the entire column iif duplicates occur

    hey there, I have been working on this for a few days now..but cant seem to make much headway. I have a spreadsheet with upto 32 columns. Among these 32 there maybe two or more duplicates. My task is to write a macro that will check through all the headers in each column, find the duplicates and delete them. A dummy sheet has been attached below to give better insight to my predicament. Plizz Help......

    NB in this case column headers C7 have been repeated.
    Attached Files Attached Files

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: comparing the column headers, then deleting the entire column iif duplicates occu

    Hello vindieselgal,

    Welcome to the Forum!

    Are you afraid of the dark? Pitch Black is one of my favorite Vin Diesel movies. This macro will remove duplicate column headers on the active worksheet, provided the headers are in row 1. This macro has been added to the attached workbook.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    06-10-2011
    Location
    helsinki, finland
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: comparing the column headers, then deleting the entire column iif duplicates occu

    wow...works like a charm!! thank you so much....if it aint too much to ask, can you give me a break down of what goes on coz i am new to VB. just a simple explanation will do...n yes pitch black is also my fave vindiesel movie :-)
    thanks again...

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: comparing the column headers, then deleting the entire column iif duplicates occu

    Hello vindieselgal,

    Here is how the macro works. The Collection object is used to hold the column numbers and column headers in row 1. This Collection object returns the column number for a given column header. If a header already exists in the collection then that header is cleared.

    The columns are then checked in reverse order for any missing (empty) headers. When found, the entire column is deleted and the remaining columns are shifted to the left. It is because of the shifting that the columns are checked in reverse order when being deleted. Otherwise the stored column numbers would not match after the first column is deleted.

  5. #5
    Registered User
    Join Date
    06-10-2011
    Location
    helsinki, finland
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: comparing the column headers, then deleting the entire column iif duplicates occu

    thanks alot Leith. could you mark this thread as solved,,,coz i cant since i guess its more than 2 days:-) have a nyce week..

+ 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