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

abdo meghari

Well-known Member
Joined
Aug 3, 2021
Messages
647
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
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
How about this?
VBA Code:
Sub test()
  Dim MAIN As Worksheet, table1 As Worksheet
  Dim table1Range As Range, MAINRange1 As Range, MAINRange2 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
      .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
  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
      .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
  Next
  End With
End Sub
 
Upvote 0
thanks , it gives mismatch error in this line
VBA Code:
.Cells(i, 2).Offset(1).Value = table1Range.Cells(Application.Match(.Cells(i, 1).Value, table1Range.Columns(1), 0), 3)
 
Upvote 0
The code will throw mismatch error when MAIN column A value is not matched in table1 column A.
In other words, table1 must contain every code and brand that exists in MAIN sheet.
 
Last edited by a moderator:
Upvote 0
just question , did you test it? in reality I copy the same data as in OP in a new file still the error shows .
 
Upvote 0
there is no file as your link !
so you wanna say if the code in column A for table1 sheet is new and is not existed in column A for MAIN sheet , then will show error?
 
Upvote 0
I think, I mean vice versa. You say, you want to double the every last code number in MAIN column A. It goes to table1 and looks for that code number. It has to be there, otherwise, how can it pull the brand name from table1 column C?

 
Upvote 0
ok I expected when fill for column E: F will not clear.
so just compare row 7 for columns B with F is not the same brand . as I said
as to column E,F should auto fill based on what precede duplicated item for the last row is existed in columns E,F
but your code will fill in column F based on TABLE1 sheet . should not do that.
the right way should fill based on precede cell (F6)
and why your file work and mine is not ?!
 
Upvote 0

Forum statistics

Threads
1,224,737
Messages
6,180,653
Members
452,992
Latest member
TokugawaIesuma

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