clear cells for duplicates items for list and sort by adjacent cells for another list

abdo meghari

Active Member
Joined
Aug 3, 2021
Messages
465
Office Version
  1. 2019
Hello
I want matching column CODE between two lists (A,E) should clear all of items are existed in A:B but not existed in E: F and sort list A: B based on list E:F ,and if items are existed in A:B and existed in E: F when sort list A: B based on list E:F should delete duplicates items from list A:B when sorting
and when sort list A:B should copy from list E:F contains empty cells for column E to list A:B . so should put two lists for adjacent cells each other of them are matched ( the same code) based on code (A,E) when sorting.


original
FILL.xlsm
ABCDEF
1CODEBRANDCODEBRAND
2BSJ100BS 1200R20 G580 JAPBSJ103BS 1200R20 R187 JAP
3BSJ100BS 1200R20 G580 JAPBSJ104BS 1200R20 R187 THI
4BSJ100BS 1200R20 G580 JAPBSJ105BS 1200R24 22PR G580
5BSJ100BS 1200R20 G580 JAPBS 1200R20 G580 TCF
6BSJ100BS 1200R20 G580 JAPBS 1200R24 G582 JAP
7BSJ101BS 1200R20 G580 THIBSJ107BS 1400R20 R180 JAP
8BSJ101BS 1200R20 G580 THIBS 1400R20 TCF 20PR R180BZ JAP
9BSJ101BS 1200R20 G580 THIBSJ109BS 1400R20 VSJ TCF JAP
10BSJ102BS 1200R24 G582 JAPBSJ110BS 155R12C R624 IND
11BSJ102BS 1200R24 G582 JAP
12BSJ102BS 1200R24 G582 JAP
13BSJ102BS 1200R24 G582 JAP
14BSJ103BS 1200R20 R187 JAP
15BSJ103BS 1200R20 R187 JAP
16BSJ104BS 1200R20 R187 THI
17BSJ105BS 1200R24 G580 JAP
18BSJ105BS 1200R24 G580 JAP
19BSJ106BS 13R22.5 R187 JAP
20BSJ107BS 1400R20 R180 JAP
21BSJ107BS 1400R20 R180 JAP
22BSJ108BS 1400R20 R180BZ JAP
23BSJ109BS 1400R20 VSJ JAP
24BSJ109BS 1400R20 VSJ JAP
25BSJ109BS 1400R20 VSJ JAP
26BSJ110BS 155R12C R624 INDO
27BSJ111BS 155R12C R623 INDO
MAIN


result
FILL.xlsm
ABCDEF
1CODEBRANDCODEBRAND
2BSJ103BS 1200R20 R187 JAPBSJ103BS 1200R20 R187 JAP
3BSJ104BS 1200R20 R187 THIBSJ104BS 1200R20 R187 THI
4BSJ105BS 1200R24 G580 JAPBSJ105BS 1200R24 22PR G580
5BS 1200R20 G580 TCFBS 1200R20 G580 TCF
6BS 1200R24 G582 JAPBS 1200R24 G582 JAP
7BSJ107BS 1400R20 R180 JAPBSJ107BS 1400R20 R180 JAP
8BS 1400R20 TCF 20PR R180BZ JAPBS 1400R20 TCF 20PR R180BZ JAP
9BSJ109BS 1400R20 VSJ TCF JAPBSJ109BS 1400R20 VSJ TCF JAP
10BSJ110BS 155R12C R624 INDBSJ110BS 155R12C R624 IND
RESULT

thanks in advance
 
Last edited:

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hi, see the linked file for a possible solution (with 10 auxiliary columns, without VBA)...

The formulas used in the table...
MAIN!I2: =IF(F2="","",IF(E2="",IF(ROW()=2,"",I1),E2))
MAIN!J2: =IF(F2="","",COUNTIF(I$2:I2,I2))
MAIN!K2: =IF(F2="","",IF(J2>IFERROR(VLOOKUP(I2,O:P,2,0),0),IF(J2>IFERROR(VLOOKUP(I2,O:Q,3,0),0),"F","n"),"n"))
MAIN!M2: =IF(B2="","",IF(AND(A2=A1,B2=B1),0,1))
MAIN!N2: =IF(B2="","",SUM(M$2:M2*(A$2:A2=A2)))
MAIN!O2: =IF(B2="","",A2)
MAIN!P2: =IF(B2="","",SUMIF(A:A,A2,M:M))
MAIN!Q2: =IF(B2="","",COUNTIF(A:A,A2))
MAIN!R2: =IF(B2="","",A2&"#"&N2)
MAIN!S2: =IF(B2="","",B2)
RESULT!A2: =IF(MAIN!F2="","",IF(MAIN!E2="","",MAIN!E2))
RESULT!B2: =IF(MAIN!F2="","",IF(MAIN!J2>IFERROR(VLOOKUP(MAIN!I2,MAIN!O:P,2,0),0),MAIN!F2,VLOOKUP(MAIN!I2&"#"&MAIN!J2,MAIN!R:S,2,0)))
RESULT!E2: =IF(MAIN!F2="","",IF(MAIN!E2="","",MAIN!E2))
RESULT!F2: =IF(MAIN!F2="","",MAIN!F2)

The formulas for Conditional Formatting...
to MAIN!F:F =K1="F"
to RESULT!B:B =MAIN!K1="F"
to RESULT!F:F =MAIN!K1="F"

FILL.xlsx

MAIN.png


RESULT.png
 
Upvote 0
This should work:
VBA Code:
Sub test()
  Dim RESULT As Worksheet
  Dim RESULTRange1 As Range, RESULTRange2 As Range, r As Range, c As Integer
 
  Worksheets("MAIN").Copy
  Set RESULT = ActiveSheet
  RESULT.Name = "RESULT"
  Set RESULTRange1 = Intersect(RESULT.UsedRange, RESULT.Range("A:B"))
  Set RESULTRange2 = Intersect(RESULT.UsedRange, RESULT.Range("E:F"))
 
  With RESULTRange1
  For i = .Rows.Count To 2 Step -1
      Set r = RESULTRange2.Columns(1).Find(what:=.Cells(i, 1).Value, LookIn:=xlFormulas, lookat:=xlWhole)
      If r Is Nothing Then
        .Cells(i, 1).Resize(, 2).Delete Shift:=xlUp
      End If
  Next
  End With
  RESULTRange1.RemoveDuplicates Columns:=Array(1, 2), Header:=xlYes
  With RESULTRange2
  For i = 2 To .Rows.Count
    If .Cells(i, 1).Value = "" Then
      RESULTRange1.Cells(Application.Match(.Cells(i, 1).End(xlUp).Value, RESULTRange1.Columns(1), 0), 1).Offset(1 + c).Resize(, 2).Insert Shift:=xlDown
      RESULTRange1.Cells(Application.Match(.Cells(i, 1).End(xlUp).Value, RESULTRange1.Columns(1), 0), 2).Offset(1 + c).Value = .Cells(i, 2).Value
      c = c + 1
    Else
      c = 0
    End If
  Next
  End With
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,110
Messages
6,123,148
Members
449,098
Latest member
Doanvanhieu

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