auto fill for two lists under last duplicates items based on matching column

abdo meghari

Active Member
Joined
Aug 3, 2021
Messages
465
Office Version
  1. 2019
Hi

I search for auto-fill the same duplicates items under last row contains duplicated item into columns A,B,E,F for sheet Main based on matching column A for table1 sheet .

in column A for MAIN sheet will insert row under last duplicated item & fill based on matching on column A for table1 sheet and auto fill in column B for MAIN sheet from column C for table1 sheet

as to column E,F should auto fill based on what precede duplicated item for the last row is existed in columns E,F and so on for the others items are existed in table1 sheet.

NUMBER.xlsm
ABCDEF
1CODEBRANDCODEBRAND
2BSJ100BS 1200 R20 18PR G580BSJ100BS 1200R20 G580 JAP
3BSJ100BS 1200R20 G580 TCFBSJ100BS 1200R20 G580 JAP
4BSJ100BS 1200 R20 18PR G580 JAPBSJ100BS 1200R20 G580 JAP
5BSJ100BS 1200R20 G580 TCF JAPBSJ100BS 1200R20 G580 JAP
6BSJ100BS 1200R20 G580 TCFBSJ100BS 1200R20 G580 JAP
7BSJ101BS 1200R20 G580 THABSJ101BS 1200R20 G580 THI
8BSJ101BS 1200 R20 18PR G580 THIBSJ101BS 1200R20 G580 THI
9BSJ101BS 1200R20 G580BSJ101BS 1200R20 G580 THI
10BSJ102BS 1200 R24 G582BSJ102BS 1200R24 G582 JAP
11BSJ102BS 1200R24 G582BSJ102BS 1200R24 G582 JAP
12BSJ102BS 1200R24 G582 JAPBSJ102BS 1200R24 G582 JAP
13BSJ102BS 1200 R24 G582 JAPBSJ102BS 1200R24 G582 JAP
14BSJ103BS 1200R20-18PR R187 JAPBSJ103BS 1200R20 R187 JAP
15BSJ103BS 1200R20 R187 TCFBSJ103BS 1200R20 R187 JAP
16BSJ104BS 1200R20-18PR R187 THIBSJ104BS 1200R20 R187 THI
17BSJ105BS 1200R24 G580BSJ105BS 1200R24 G580 JAP
18BSJ105BS 1200R24 G580 JAPBSJ105BS 1200R24 G580 JAP
19BSJ106BS 13 R22.5 R187 JAPBSJ106BS 13R22.5 R187 JAP
20BSJ107BS 1400R20 TCF R180 JAPBSJ107BS 1400R20 R180 JAP
21BSJ107BS 1400R20 TCF R180BSJ107BS 1400R20 R180 JAP
22BSJ108BS 1400R20 TCF R180BZ JAPBSJ108BS 1400R20 R180BZ JAP
23BSJ109BS 1400R20VSJ TCF JAPBSJ109BS 1400R20 VSJ JAP
24BSJ109BS 1400R20 VSJ TCF JAPBSJ109BS 1400R20 VSJ JAP
25BSJ109BS 1400R20 VSJ TCFBSJ109BS 1400R20 VSJ JAP
26BSJ110BS 155 R12C R624 INDBSJ110BS 155R12C R624 INDO
27BSJ111BS 155R12C R623 INDBSJ111BS 155R12C R623 INDO
Main



NUMBER.xlsm
ABCDE
1S.NITEMitempursel
2BSJ1011BS 1200 R20 18PR G580 THI6.00
3BSJ1002BS 1200 R20 18PR G580 JAP1.00818.00
4BSJ1033BS 1200R20-18PR R187 JAP8.006.00
5BSJ1054BS 1200R24 G580 JAP4.00
6BSJ1025BS 1200R24 G582 JAP2.00
7BSJ1066BS 13 R22.5 R187 JAP3.00
8BSJ1077BS 1400R20 TCF R180 JAP12.00
9BSJ1098BS 1400R20VSJ TCF JAP22.00
10BSJ1329BS 195/60 R15 EP150 THI14.00
table1
Cell Formulas
RangeFormula
E3E3=490+278+50




I put some result how should be as highlighted how add them
NUMBER.xlsm
ABCDEF
1CODEBRANDCODEBRAND
2BSJ100BS 1200 R20 18PR G580BSJ100BS 1200R20 G580 JAP
3BSJ100BS 1200R20 G580 TCFBSJ100BS 1200R20 G580 JAP
4BSJ100BS 1200 R20 18PR G580 JAPBSJ100BS 1200R20 G580 JAP
5BSJ100BS 1200R20 G580 TCF JAPBSJ100BS 1200R20 G580 JAP
6BSJ100BS 1200R20 G580 TCFBSJ100BS 1200R20 G580 JAP
7BSJ100BS 1200 R20 18PR G580 JAPBSJ100BS 1200R20 G580 JAP
8BSJ101BS 1200R20 G580 THABSJ101BS 1200R20 G580 THI
9BSJ101BS 1200 R20 18PR G580 THIBSJ101BS 1200R20 G580 THI
10BSJ101BS 1200R20 G580BSJ101BS 1200R20 G580 THI
11BSJ101BS 1200 R20 18PR G580 THIBSJ101BS 1200R20 G580 THI
12BSJ102BS 1200 R24 G582BSJ102BS 1200R24 G582 JAP
13BSJ102BS 1200R24 G582BSJ102BS 1200R24 G582 JAP
14BSJ102BS 1200R24 G582 JAPBSJ102BS 1200R24 G582 JAP
15BSJ102BS 1200 R24 G582 JAPBSJ102BS 1200R24 G582 JAP
16BSJ102BS 1200R24 G582 JAPBSJ102BS 1200R24 G582 JAP
17BSJ103BS 1200R20-18PR R187 JAPBSJ103BS 1200R20 R187 JAP
18BSJ103BS 1200R20 R187 TCFBSJ103BS 1200R20 R187 JAP
19BSJ103BS 1200R20-18PR R187 JAPBSJ103BS 1200R20 R187 JAP
20BSJ104BS 1200R20-18PR R187 THIBSJ104BS 1200R20 R187 THI
21BSJ105BS 1200R24 G580BSJ105BS 1200R24 G580 JAP
22BSJ105BS 1200R24 G580 JAPBSJ105BS 1200R24 G580 JAP
23BSJ105BS 1200R24 G580 JAPBSJ105BS 1200R24 G580 JAP
24BSJ106BS 13 R22.5 R187 JAPBSJ106BS 13R22.5 R187 JAP
25BSJ107BS 1400R20 TCF R180 JAPBSJ107BS 1400R20 R180 JAP
26BSJ107BS 1400R20 TCF R180BSJ107BS 1400R20 R180 JAP
27BSJ108BS 1400R20 TCF R180BZ JAPBSJ108BS 1400R20 R180BZ JAP
Main
 
yo mean it goes from table1 sheet to MAIN sheet .
No, let me put in order.
First it goes MAIN A7. It sees that BSJ100 is the last number. It lookup the number in table1 column A. Finds at table1 A3. Copies the information from table1 C3 to MAIN B7.
It goes the same for other numbers until BSJ104 at MAIN A20. It looks at table1 column A. Can not find it. It throws the error.

Oh, wait a minute, would you like to skip it if it cannot finds?
 
Upvote 0

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
First it goes MAIN A7. It sees that BSJ100 is the last number. It lookup the number in table1 column A. Finds at table1 A3. Copies the information from table1 C3 to MAIN B7.
that's correct .
It goes the same for other numbers until BSJ104 at MAIN A20. It looks at table1 column A. Can not find it. It trows the error.
should not interest what is existed in MAIN sheet and is not existed in TABLE1 sheet .
the most important what's is existed for two sheets .
 
Upvote 0
Then this should work:
VBA Code:
Sub test()
  Dim MAIN As Worksheet, table1 As Worksheet
  Dim table1Range As Range, MAINRange1 As Range, MAINRange2 As Range, r As Range
  
  Set MAIN = Worksheets("MAIN")
  Set MAINRange1 = Intersect(MAIN.UsedRange, MAIN.Range("A:B"))
  Set MAINRange2 = Intersect(MAIN.UsedRange, MAIN.Range("E:F"))
  
  Set table1 = Worksheets("table1")
  Set table1Range = Intersect(table1.UsedRange, table1.Range("A:C"))
  
  With MAINRange1
  For i = .Rows.Count To 2 Step -1
    If .Cells(i, 1).Offset(1).Value <> .Cells(i, 1).Value Then
      Set r = table1Range.Columns(1).Find(what:=.Cells(i, 1).Value, LookIn:=xlFormulas, lookat:=xlWhole)
      If Not r Is Nothing Then
        .Cells(i, 1).Offset(1).Resize(, 2).Insert Shift:=xlDown
        .Cells(i, 1).Offset(1).Value = .Cells(i, 1).Value
        .Cells(i, 2).Offset(1).Value = table1Range.Cells(Application.Match(.Cells(i, 1).Value, table1Range.Columns(1), 0), 3)
      End If
    End If
  Next
  End With
  With MAINRange2
  For i = .Rows.Count To 2 Step -1
    If .Cells(i, 1).Offset(1).Value <> .Cells(i, 1).Value Then
      Set r = table1Range.Columns(1).Find(what:=.Cells(i, 1).Value, LookIn:=xlFormulas, lookat:=xlWhole)
      If Not r Is Nothing Then
        .Cells(i, 1).Offset(1).Resize(, 2).Insert Shift:=xlDown
        .Cells(i, 1).Offset(1).Resize(, 2).Value = .Cells(i, 1).Resize(, 2).Value
      End If
    End If
  Next
  On Error GoTo 0
  End With
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,326
Messages
6,124,265
Members
449,149
Latest member
mwdbActuary

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