+ Reply to Thread
Results 1 to 22 of 22

Remove duplicate adjacent rows

  1. #1
    Registered User
    Join Date
    06-05-2023
    Location
    Lommel, Belgium
    MS-Off Ver
    Office365
    Posts
    6

    Remove duplicate adjacent rows

    Hi,

    I have 4 columns with data. This is a thickness measurement of a textile on 4 different positions.
    I like to remove all the identical adjacent rows.

    I found a way to remove duplicate rows, but i only like to remove them if they are duplicate AND adjacent.
    Anyone an idea to do this?

    Kind regards,
    Maarten
    Attached Files Attached Files

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,889

    Re: Remove duplicate adjacent rows

    Welcome to the forum.

    You may well require VBA for this - shall I move the thread for you?
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    06-05-2023
    Location
    Lommel, Belgium
    MS-Off Ver
    Office365
    Posts
    6

    Re: Remove duplicate adjacent rows

    Yes please! Feel free to move it to the right position on this forum!

    Thanks!

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,889

    Re: Remove duplicate adjacent rows

    Thread moved.

    Your sample file should include an example of before AND after scenarios. It should not just be a data dump.

    EDIT: And it should be a small sample - limit it to 100 rows, please.
    Last edited by AliGW; 06-05-2023 at 04:55 AM. Reason: Typo fixed.

  5. #5
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Remove duplicate adjacent rows

    Hi Maarten - do you want to remove the first instance AND the duplicates, or just the duplicates?
    Clicking the Add Reputation star below helpful posts is a great way to show your appreciation.
    Please mark your threads as SOLVED upon conclusion (Thread Tools above Post # 1). - Lee

  6. #6
    Registered User
    Join Date
    06-05-2023
    Location
    Lommel, Belgium
    MS-Off Ver
    Office365
    Posts
    6

    Re: Remove duplicate adjacent rows

    What do you mean with after scenarios?

    This is the raw data. This is the thickness of a textile measured with a measuring tool on 4 positions on a textile.
    This measurement is done during cutting of the textile with a sampling frequency of 1 second.

    The cutting process is as follows:
    Roll to sheet principle --> 60 seconds (=60 measurements) during the cutting procedure and 6 seconds (=6 measurements) during transport/feed of the textile roll.

    As you can see in the data. Around 60 adjacent positions are identical (= cutting procedure) and then around 6 adjacent positions are different. I only like the keep the 6 positions during transport.
    The difficult part is that the 60 identical positons are nog always 60.

    Normally around 210 sheets are transported, so i should reduce this file from 14000 datapoints to around 1200 datapoints (taken during transport)

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,889

    Re: Remove duplicate adjacent rows

    See the question in post #5.

    A before and after sample workbook would make it clear what you were expecting to happen. You have provided 1000s of rows of data with not one bit of annotation. Of course, you know what you want, but you need to convey that clearly to your helpers.

  8. #8
    Registered User
    Join Date
    06-05-2023
    Location
    Lommel, Belgium
    MS-Off Ver
    Office365
    Posts
    6

    Re: Remove duplicate adjacent rows

    I only like to remove a row if the duplicate value is adjacent.

  9. #9
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,889

    Re: Remove duplicate adjacent rows

    Which of these rows needs removing and why?

    AliGW on MS365 Beta Channel (Windows 11) 64 bit

    A
    B
    C
    D
    E
    4
    1
    0.259
    0.344
    0.244
    0.162
    5
    2
    0.259
    0.344
    0.244
    0.162
    6
    3
    0.259
    0.344
    0.244
    0.162
    7
    4
    0.259
    0.344
    0.244
    0.162
    8
    5
    0.259
    0.344
    0.244
    0.162
    9
    6
    0.259
    0.344
    0.244
    0.162
    10
    7
    0.259
    0.344
    0.244
    0.162
    11
    8
    0.259
    0.344
    0.244
    0.162
    12
    9
    0.259
    0.344
    0.244
    0.162
    13
    10
    0.259
    0.344
    0.244
    0.162
    14
    11
    0.259
    0.344
    0.251
    0.162
    15
    12
    0.259
    0.344
    0.251
    0.162
    16
    13
    0.259
    0.344
    0.251
    0.162
    17
    14
    0.259
    0.344
    0.252
    0.162
    18
    15
    0.259
    0.344
    0.252
    0.162
    19
    16
    0.259
    0.344
    0.252
    0.162
    20
    17
    0.259
    0.344
    0.252
    0.162
    21
    18
    0.259
    0.344
    0.252
    0.162
    22
    19
    0.259
    0.344
    0.252
    0.162
    23
    20
    0.259
    0.344
    0.252
    0.162
    24
    21
    0.259
    0.344
    0.252
    0.162
    25
    22
    0.259
    0.344
    0.252
    0.162
    26
    23
    0.259
    0.344
    0.252
    0.162
    27
    24
    0.259
    0.344
    0.252
    0.162
    28
    25
    0.259
    0.344
    0.252
    0.162
    29
    26
    0.259
    0.344
    0.252
    0.162
    30
    27
    0.259
    0.344
    0.253
    0.162
    31
    28
    0.259
    0.344
    0.253
    0.162
    Sheet: Blad1

  10. #10
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Remove duplicate adjacent rows

    Quote Originally Posted by MaartenColaers View Post
    I only like to remove a row if the duplicate value is adjacent.
    Yes , but if 60 rows are identical and adjacent, do you want to remove all 60, or just 59, leaving 1?
    Also, is it possible that there will be identical rows within the parts you want to keep?

  11. #11
    Registered User
    Join Date
    06-05-2023
    Location
    Lommel, Belgium
    MS-Off Ver
    Office365
    Posts
    6

    Re: Remove duplicate adjacent rows

    Sorry for the haziness. It is my first post, but i have to be more clear from the beginning
    I like to keep indeed one value, so "around' 60 identical and adjacent values to 1 value. (so removing 59 identical values)

    As you can see, sometimes in one column there are '60' identical values, but in the other columns there is 1 value changing. I think we need to use only one column to look for the duplicates and then broaden the selection to the other columns.
    Last edited by AliGW; 06-05-2023 at 05:23 AM. Reason: Please do NOT quote unnecessarily!

  12. #12
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,889

    Re: Remove duplicate adjacent rows

    Does this give what you want?

    =UNIQUE(B4:E13195)

    Can you please provide a SMALL sample dataset showing before and after?

  13. #13
    Valued Forum Contributor
    Join Date
    06-27-2010
    Location
    sYRIA
    MS-Off Ver
    Excel 2013
    Posts
    669

    Re: Remove duplicate adjacent rows

    Hi
    May be
    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    06-05-2023
    Location
    Lommel, Belgium
    MS-Off Ver
    Office365
    Posts
    6

    Re: Remove duplicate adjacent rows

    Attachment 831846

    Attached, you can see what i like to become.
    The function should only work on one column and broaden to change to the other columns.
    In this example the one column is B3:B26 and despite the change from C7 to C8, these values are not kept.

  15. #15
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,889

    Re: Remove duplicate adjacent rows

    Did you try my suggestion? Did you try post #13? If so, in what way did they NOT meet your requirements?

    You are illustrating now with a different dataset to the one you shared.

    Share the dataset that you are using to illustrate the issue. Workbook - NOT a screenshot!

  16. #16
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Remove duplicate adjacent rows

    Your data doesn't really line up so neatly as you describe. I used this formula (in F5, copied down):
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    ...to look at the aggregate difference between each row and the one above it (0 = identical). As shown below, the values sometimes jump around rather randomly.
    Row\Col
    A
    B
    C
    D
    E
    F
    122
    119
    0.259
    0.354
    0.275
    0.15
    0
    123
    120
    0.259
    0.354
    0.275
    0.15
    0
    124
    121
    0.259
    0.354
    0.275
    0.15
    0
    125
    122
    0.348
    0.428
    0.32
    0.232
    0.29
    126
    123
    0.347
    0.443
    0.31
    0.254
    0.026
    127
    124
    0.387
    0.493
    0.353
    0.264
    0.143
    128
    125
    0.47
    0.51
    0.306
    0.242
    0.031
    129
    126
    0.423
    0.495
    0.311
    0.187
    -0.112
    130
    127
    0.423
    0.494
    0.311
    0.185
    -0.003
    131
    128
    0.423
    0.494
    0.311
    0.184
    -0.001
    132
    129
    0.423
    0.493
    0.311
    0.183
    -0.002
    133
    130
    0.422
    0.471
    0.311
    0.182
    -0.024
    134
    131
    0.422
    0.464
    0.308
    0.172
    -0.02
    135
    132
    0.422
    0.464
    0.307
    0.169
    -0.004
    136
    133
    0.421
    0.464
    0.307
    0.168
    -0.002
    137
    134
    0.421
    0.464
    0.307
    0.168
    0
    138
    135
    0.421
    0.464
    0.306
    0.167
    -0.002
    139
    136
    0.421
    0.464
    0.306
    0.167
    0
    140
    137
    0.421
    0.462
    0.305
    0.164
    -0.006
    141
    138
    0.421
    0.462
    0.305
    0.163
    -0.001
    142
    139
    0.421
    0.462
    0.305
    0.163
    0
    143
    140
    0.421
    0.462
    0.305
    0.163
    0
    144
    141
    0.421
    0.462
    0.305
    0.163
    0
    145
    142
    0.421
    0.462
    0.305
    0.162
    -0.001
    146
    143
    0.421
    0.462
    0.305
    0.161
    -0.001
    147
    144
    0.421
    0.462
    0.305
    0.161
    0
    148
    145
    0.421
    0.462
    0.305
    0.161
    0
    149
    146
    0.421
    0.462
    0.305
    0.161
    0
    150
    147
    0.421
    0.462
    0.305
    0.16
    -0.001
    151
    148
    0.421
    0.462
    0.305
    0.16
    0

  17. #17
    Registered User
    Join Date
    12-30-2021
    Location
    Toronto
    MS-Off Ver
    365
    Posts
    51

    Re: Remove duplicate adjacent rows

    Rows 414 and 417 are identical. I guess you want to keep them both since row 416 is different from them. In the meantime, you want to delete row 415. Consider you are using 365, if you can see Automate in your tab menu, the following Script will do the job. Backup your data first. Worksheet Result contains 4303 rows.
    Please Login or Register  to view this content.
    Last edited by Torontohrb; 06-05-2023 at 10:15 AM.

  18. #18
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,889

    Re: Remove duplicate adjacent rows

    Office Scripts is only available in Enterprise and educational versions of Office 365 - a standalone user won't have it.

  19. #19
    Registered User
    Join Date
    12-30-2021
    Location
    Toronto
    MS-Off Ver
    365
    Posts
    51

    Re: Remove duplicate adjacent rows

    Scripts is powerful to deal with arrays. If using VBA, it is also easy. Just loop through from bottom to top: If the current row is identical to the previous one, delete the row.

  20. #20
    Registered User
    Join Date
    12-30-2021
    Location
    Toronto
    MS-Off Ver
    365
    Posts
    51

    Re: Remove duplicate adjacent rows

    Here is the VBA code. Comparing with Scripts, VBA is much slower.
    Please Login or Register  to view this content.

  21. #21
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Remove duplicate adjacent rows

    Quote Originally Posted by MaartenColaers View Post
    I found a way to remove duplicate rows, but i only like to remove them if they are duplicate AND adjacent.
    Have you tired RemoveDuplicates?
    Please Login or Register  to view this content.

  22. #22
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Remove duplicate adjacent rows

    This removes adjacent duplicates. You can reset the LOWER_LIMIT constant higher to remove more rows i.e. those that vary by insignificant amounts.
    Please Login or Register  to view this content.
    I made a copy of Blad1 ("Blad1 (2)") so I could restore the data for testing purposes.
    You can do the same; just make the copy (before running this) and un-comment the lines in red.

    PS. Could you just filter the data, as I did, without removing the rows? You could adjust the filtering formula to read lower limit from a cell.
    Last edited by leelnich; 06-05-2023 at 04:02 PM.

+ 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. How to remove duplicate Rows
    By Merrysa in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-20-2019, 03:30 AM
  2. [SOLVED] How to sum duplicate values then remove the duplicate rows?
    By terry3218 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 12-12-2015, 02:38 AM
  3. [SOLVED] Remove Duplicate rows
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-13-2015, 02:34 PM
  4. excel macro to remove specific columns and rows + remove duplicate
    By garrywelson in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 01-17-2013, 12:03 PM
  5. Excel 2007 : Remove duplicate rows
    By springprogressive in forum Excel General
    Replies: 1
    Last Post: 09-05-2011, 07:32 AM
  6. [SOLVED] Remove duplicate rows
    By Vestlink in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-01-2010, 05:36 AM
  7. [SOLVED] How do I remove Duplicate rows?
    By 85225 in forum Excel General
    Replies: 14
    Last Post: 04-03-2006, 01:30 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