clear duplicated items in specific columns and arrange below for each item based on column

Mussa

Active Member
Joined
Jul 12, 2021
Messages
264
Office Version
  1. 2019
  2. 2010
hi
I search for macro to clear repeated items in COL A and arrange again below for each item .



sheet data
ttt.xlsm
ABCDEF
1DEL NOBATCH NO TTLTT1IMPORTEXPORT
2CCD-1CC-1SS-1TRU1210
3CCD-1CC-1SS-1LTR125
4CCD-1CC-2SS-2FG55
5CCS-2CC-1SS-1TRR105
6CCS-2CC-1SS-1LTR2010
7CSD-1CS-1LL-1RRL155
8CSD-1CS-2LL-2TTY1010
9CCD-1CS-3LL-3MMW2010
10CCLCS-4LL-4NNW1010
11CCLCC-2SS-2LTR215
12CCMCC-3SS-3LTR225
13CSD-1CS-1LL-1RRL155
DATA


expected result
sheet result
ttt.xlsm
ABCDEF
1DEL NOBATCH NO TTLTT1IMPORTEXPORT
2CCD-1CC-1SS-1TRU1210
3CC-1SS-1LTR125
4CC-2SS-2FG55
5CS-3LL-3MMW2010
6CCS-2CC-1SS-1TRR105
7CC-1SS-1LTR2010
8CSD-1CS-1LL-1RRL155
9CS-2LL-2TTY1010
10CS-1LL-1RRL155
11CCLCS-4LL-4NNW1010
12CC-2SS-2LTR215
13CCMCC-3SS-3LTR225
RESULT
 
My mistake. The way I wrote the 'Evaluate' line did allow for different sheets being active when the code was rune. try this version.

Rich (BB code):
Sub Mussa_v2a()
  With Sheets("Sheet2")
    'Clear any existing data
    .UsedRange.Clear
    'Copy the table from Sh1 to Sh2
    Sheets("Sheet1").Range("A1").CurrentRegion.Copy .Range("A1")
    With .Range("A1").CurrentRegion
      'Sort based on column A to get all the groups together
      .Sort Key1:=.Columns(1), Order1:=xlAscending, Header:=xlYes
      With .Columns(1).Offset(1).Resize(.Rows.Count - 1)
        'Look at the column A cells from row 2 down and replace with True if they are the same as the cell above
        .Value = Evaluate(Replace(Replace("if(#=%,True,#)", "#", .Address(External:=True)), "%", .Offset(-1).Address(External:=True)))
        'Clear contents from all cells that contain True
        On Error Resume Next
        .SpecialCells(xlConstants, xlLogical).ClearContents
        On Error GoTo 0
      End With
    End With
  End With
End Sub
 
Upvote 0
Solution

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
You're welcome. Glad we could help. Thanks for the follow-up. :)
 
Upvote 0

Forum statistics

Threads
1,223,914
Messages
6,175,351
Members
452,638
Latest member
Oluwabukunmi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top