+ Reply to Thread
Results 1 to 4 of 4

Check and Remove duplicates Horizontally (Within ROW)

Hybrid View

winmaxservices1 Check and Remove duplicates... 04-04-2015, 03:31 AM
JasperD Re: Check and Remove... 04-04-2015, 04:05 AM
winmaxservices1 Re: Check and Remove... 04-04-2015, 04:26 AM
JasperD Re: Check and Remove... 04-04-2015, 04:38 AM
  1. #1
    Forum Contributor
    Join Date
    03-12-2014
    Location
    India
    MS-Off Ver
    Excel 2013
    Posts
    118

    Check and Remove duplicates Horizontally (Within ROW)

    Hi,

    I have a data in sheet1. Column A is Serial number and data starts from Column B till the end.

    I want to remove the duplicate values within a row. and paste a data (Without duplicates) in a new sheet2

    Note : - we will be adding data in rows and columns from time to time.

    Please refer attachment.
    Attached Files Attached Files

  2. #2
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Check and Remove duplicates Horizontally (Within ROW)

    Try this:

    Sub excelforum()
    Dim unique$
    Sheet2.Cells.ClearContents
    For Each Row In Sheet1.Range("A1:A" & Sheet1.Cells(Rows.Count, 1).End(xlUp).Row)
        For Each Column In Sheet1.Range(Cells(Row, 2), Sheet1.Cells(Row, Cells(Row, Columns.Count).End(xlToLeft).Column))
            If Not Column = vbNullString And InStr(unique, Column) = 0 Then
            unique = unique & Column & ","
            Sheet2.Cells(Row, Sheet2.Cells(Row, Columns.Count).End(xlToLeft).Column).Offset(0, 1) = Column
            End If
        Next Column
    unique = vbnulstring
    Next Row
    
    End Sub
    Please click the * below if this helps

  3. #3
    Forum Contributor
    Join Date
    03-12-2014
    Location
    India
    MS-Off Ver
    Excel 2013
    Posts
    118

    Re: Check and Remove duplicates Horizontally (Within ROW)

    it shows error in following line

    If Not Column = vbNullString And InStr(unique, Column) = 0 Then

  4. #4
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Check and Remove duplicates Horizontally (Within ROW)

    Weird, worked for me.
    but I have to admit I used lazy coding.

    Adjust as follows:

    Sub excelforum()
    Dim unique$, rw As Range, col As Range
    Sheet2.Cells.ClearContents
    For Each rw In Sheet1.Range("A1:A" & Sheet1.Cells(Rows.Count, 1).End(xlUp).Row)
        For Each col In Sheet1.Range(Cells(rw.Row, 2), Sheet1.Cells(rw.Row, Sheet1.Cells(rw.Row, Columns.Count).End(xlToLeft).Column))
            If Not col = vbNullString And InStr(unique, col) = 0 Then
            unique = unique & col & ","
            Sheet2.Cells(rw.Row, Sheet2.Cells(rw.Row, Columns.Count).End(xlToLeft).Column).Offset(0, 1) = col
            End If
        Next col
    unique = vbnulstring
    Next rw
    
    End Sub
    Last edited by JasperD; 04-04-2015 at 04:47 AM.

+ 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. return multiple values horizontally while removing duplicates
    By kingi in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-24-2013, 03:55 PM
  2. Replies: 1
    Last Post: 10-23-2012, 09:12 AM
  3. Replies: 5
    Last Post: 02-28-2012, 02:52 PM
  4. Replies: 2
    Last Post: 03-20-2011, 11:19 AM
  5. Macro to check for blank cell entry, copy previous value, and check for duplicates
    By xPunxNotDeadx in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-26-2009, 06: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