+ Reply to Thread
Results 1 to 4 of 4

Remove Duplicates and Spaces within a Range in a Row

  1. #1
    Forum Contributor
    Join Date
    06-21-2010
    Location
    -
    MS-Off Ver
    Excel 2010
    Posts
    1,211

    Remove Duplicates and Spaces within a Range in a Row

    I have a spreadsheet with around 5,000 rows. Looking at the sheet on a row by row basis, within Columns D to P there are a number of duplicate entries. Is there any way of removing the duplicates within a row (rather than a column) and also removing the spaces this leaves.

    I've attached a basic sample to demonstrate what I have as a starting point and what I need to end up with. Removing the duplicates within each row for columns D to P and moving the items to remove the spaces this leaves on a row by row basis manually takes for ever.

    Many thanks

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Remove Duplicates and Spaces within a Range in a Row

    Hi, Hangman,

    maybe have a look at the code supplied by hiker95 in http://www.mrexcel.com/forum/excel-q...ml#post3696619 which may be adapted to suit your needs.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Forum Contributor
    Join Date
    06-21-2010
    Location
    -
    MS-Off Ver
    Excel 2010
    Posts
    1,211

    Re: Remove Duplicates and Spaces within a Range in a Row

    Hi Holger,

    This code seems to remove 'all' duplicates. What I need to try and achieve is to only remove duplciates when they apper on the same row and within that row. It may be that say 'Red' appears on several rows. I would only want to remove red (and any other duplicates) where they appear more than once on the same row, not across the whole sheet, as per the sample I posted.

    My VBA is very limited, so unsure how I would go about adapting the code to achieve this...

    Many thanks

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Remove Duplicates and Spaces within a Range in a Row

    Hi, Hanman,

    maybe try this code which goes into a standard module and should be tried on a copy of the worksheet without the expected result below.

    Please Login or Register  to view this content.
    How to install your new code
    1. Copy the Excel VBA code
    2. Select the workbook in which you want to store the Excel VBA code
    3. Press Alt+F11 to open the Visual Basic Editor
    4. Choose Insert > Module
    5. Edit > Paste the macro into the module that appeared
    6. Close the VBEditor
    7. Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)

    To run the Excel VBA code:
    1. Press Alt-F8 to open the macro list
    2. Select a macro in the list
    3. Click the Run button
    Ciao,
    Holger

+ 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. Range in Remove duplicates
    By nsv in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-11-2012, 05:33 AM
  2. Replies: 5
    Last Post: 02-28-2012, 02:52 PM
  3. Replies: 6
    Last Post: 08-18-2011, 05:25 PM
  4. Replies: 5
    Last Post: 07-25-2011, 09:42 PM
  5. Remove Duplicates in a Dynamic Range using Excel 2007
    By nsorden in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-22-2009, 10:24 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