autofill for 11,200 rows based on matching between two sheets with another

Hasson

Active Member
Joined
Apr 8, 2021
Messages
406
Office Version
  1. 2016
Platform
  1. Windows
good morning !
I want matching data between two sheets (sheet1,2) based on column B with sheet RES and fill the values from column H:L in sheet RES .
should brings the values from columns F for sheets 1,2 and put in columns H,I after that the column J=column G * column H and column K= column G* column I and column L= column J-column K . the data colud be more than 11000 rows across sheets
PUR1.xlsx
ABCDEFG
1ITEMCODEDESCIBEPRODUCTION BYQTYUNIT PRICETOTAL
21/1/2021ATR-A100CLA1 23M-1IT200.000200.00040,000.000
31/2/2021ATR-A101CLA2 VBG LCHI300.000300.00090,000.000
41/3/2021ATR-A102CLA3TAI400.000400.000160,000.000
51/4/2021ATR-A103CLA4TR500.000500.000250,000.000
61/5/2021ATR-A104CLA5EG600.000600.000360,000.000
71/6/2021ATR-A105M230TU700.000700.000490,000.000
81/7/2021ATR-A106CLA7US800.000800.000640,000.000
91/8/2021ATR-A107CLA8UK900.000900.000810,000.000
101/9/2021ATR-A108CLA9 NBR1,000.0001,000.0001,000,000.000
111/10/2021ATR-A109CLA10IT1,100.0001,100.0001,210,000.000
121/11/2021ATR-A110LVDCH1,200.0001,200.0001,440,000.000
131/12/2021ATR-A111CLA12JA1,300.0001,300.0001,690,000.000
141/13/2021ATR-A112CLA13TR1,400.0001,400.0001,960,000.000
151/14/2021ATR-A113CLA14 SS230EG1,500.0001,500.0002,250,000.000
161/15/2021ATR-A114CLA15TU1,600.0001,600.0002,560,000.000
171/16/2021ATR-A115CLA16US1,700.0001,700.0002,890,000.000
181/17/2021ATR-A116CLA17UK1,800.0001,800.0003,240,000.000
191/18/2021ATR-A117RRSDFBR1,900.0001,900.0003,610,000.000
201/19/2021ATR-A118CLA19IT2,000.0002,000.0004,000,000.000
211/20/2021ATR-A119CLA20CHI2,100.0002,100.0004,410,000.000
221/21/2021BBTR-A120CLA21IT2,200.0002,200.0004,840,000.000
231/22/2021BBTR-A121CLA22CHI2,300.0002,300.0005,290,000.000
241/23/2021BBTR-A122CLA23IT2,400.0002,400.0005,760,000.000
251/24/2021BBTR-A123CLA24CHI2,500.0002,500.0006,250,000.000
261/25/2021BBTR-A124CLA25IT2,600.0002,600.0006,760,000.000
271/26/2021BBTR-A125CLA26CHI2,700.0002,700.0007,290,000.000
281/27/2021BBTR-A126CLA27IT2,800.0002,800.0007,840,000.000
291/28/2021BBTR-A127CLA28CHI2,900.0002,900.0008,410,000.000
301/29/2021BBTR-A128CLA29IT3,000.0003,000.0009,000,000.000
311/30/2021BBTR-A129CLA30CHI3,100.0003,100.0009,610,000.000
sheet1
Cell Formulas
RangeFormula
G2:G31G2=E2*F2




PUR1.xlsx
ABCDEFG
1ITEMCODEDESCIBEPRODUCTION BYQTYUNIT PRICETOTAL
21/1/2021ATR-A100CLA1 23M-1IT200.000220.00044,000.000
31/2/2021ATR-A101CLA2 VBG LCHI300.000330.00099,000.000
41/3/2021ATR-A102CLA3TAI400.000450.000180,000.000
51/4/2021ATR-A103CLA4TR500.000560.000280,000.000
61/5/2021ATR-A104CLA5EG600.000622.000373,200.000
71/6/2021ATR-A105M230TU700.000722.000505,400.000
81/7/2021ATR-A106CLA7US800.000870.000696,000.000
91/8/2021ATR-A107CLA8UK900.000920.000828,000.000
101/9/2021ATR-A108CLA9 NBR1,000.000900.000900,000.000
111/10/2021ATR-A109CLA10IT1,100.000860.000946,000.000
121/11/2021ATR-A110LVDCH1,200.000980.0001,176,000.000
131/12/2021ATR-A111CLA12JA1,300.000456.000592,800.000
141/13/2021ATR-A112CLA13TR1,400.000234.000327,600.000
151/14/2021ATR-A113CLA14 SS230EG1,500.000678.0001,017,000.000
161/15/2021ATR-A114CLA15TU1,600.000234.000374,400.000
171/16/2021ATR-A115CLA16US1,700.0001,200.0002,040,000.000
181/17/2021ATR-A116CLA17UK1,800.0001,300.0002,340,000.000
191/18/2021ATR-A117RRSDFBR1,900.0001,400.0002,660,000.000
201/19/2021ATR-A118CLA19IT2,000.0001,500.0003,000,000.000
211/20/2021ATR-A119CLA20CHI2,100.0001,666.0003,498,600.000
SHEET2
Cell Formulas
RangeFormula
G2:G21G2=E2*F2



should be result
PUR1.xlsx
BCDEFGHIJKL
1CODEDESCIBEPRODUCTION BYQTYSTQTNMQTYUNIT PRICEUNIT PRICE1TOTALTOTAL1BALANCE
2ATR-A107CLA8UK2,099.000123.000900.000900.000900.000810,000.000810,000.0000.000
3ATR-A101CLA2 VBG LCHI300.000100.000300.000900.000300.000270,000.00090,000.000180,000.000
4ATR-A102CLA3TAI120.000120.000400.000900.000400.000360,000.000160,000.000200,000.000
5ATR-A100CLA1 23M-1IT100.000120.000200.000900.000200.000180,000.00040,000.000140,000.000
6ATR-A103CLA4TR20.000122.000500.000900.000500.000450,000.000250,000.000200,000.000
7ATR-A104CLA5EG20.00011.000600.000900.000600.000540,000.000360,000.000180,000.000
8ATR-A105M230TU20.00012.000700.000900.000700.000630,000.000490,000.000140,000.000
9ATR-A106CLA7US20.00011.000800.000900.000800.000720,000.000640,000.00080,000.000
RES
Cell Formulas
RangeFormula
J2:J9J2=G2*H2
K2:K9K2=I2*G2
L2:L9L2=J2-K2
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Try below VBA code;
Hit Alt-F11 to open VBA edit window, insert/module, paste below code then hit F5 to run:
VBA Code:
Option Explicit
Sub add()
Dim i&, j&, s1, s2, res
With Sheets("Sheet1")
    s1 = .Range("A2:F" & .Cells(Rows.Count, "A").End(xlUp).Row).Value
End With
With Sheets("Sheet2")
    s2 = .Range("A2:F" & .Cells(Rows.Count, "A").End(xlUp).Row).Value
End With
With Sheets("RES")
    res = .Range("B2:L" & .Cells(Rows.Count, "B").End(xlUp).Row).Value
For i = 1 To UBound(res)
    For j = 1 To UBound(s1)
        If res(i, 1) = s1(j, 2) Then
            res(i, 8) = s1(j, 6)
            res(i, 10) = res(i, 6) * res(i, 8)
            Exit For
        End If
    Next
    For j = 1 To UBound(s2)
        If res(i, 1) = s2(j, 2) Then
            res(i, 7) = s2(j, 6)
            res(i, 9) = res(i, 6) * res(i, 7)
            res(i, 11) = res(i, 9) - res(i, 10)
            Exit For
        End If
    Next
Next
.Range("H2:L1000000").ClearContents
.Range("B2").Resize(UBound(res), UBound(res, 2)).Value = res
End With
End Sub
 
Upvote 0
thanks . it shows a problem as highlighted in two last rows
somtimes I have data is in sheet1 but are not existed in sheet2 as in example BBTR-A129 , data are in sheet2 but not existed in sheet1 as example ATR-A120 .
this is what I got
PUR1.xlsx
ABCDEFGHIJKL
1ITEMCODEDESCIBEPRODUCTION BYQTYSTQTNMQTYUNIT PRICEUNIT PRICE1TOTALTOTAL1BALANCE
21/1/2021ATR-A107CLA8UK2,099.000123.000900.000920.000900.000828,000.000810,000.00018,000.000
31/2/2021ATR-A101CLA2 VBG LCHI300.000100.000300.000330.000300.00099,000.00090,000.0009,000.000
41/3/2021ATR-A102CLA3TAI120.000120.000400.000450.000400.000180,000.000160,000.00020,000.000
51/4/2021ATR-A100CLA1 23M-1IT100.000120.000200.000220.000200.00044,000.00040,000.0004,000.000
61/5/2021ATR-A103CLA4TR20.000122.000500.000560.000500.000280,000.000250,000.00030,000.000
71/6/2021ATR-A104CLA5EG20.00011.000600.000622.000600.000373,200.000360,000.00013,200.000
81/7/2021ATR-A105M230TU20.00012.000700.000722.000700.000505,400.000490,000.00015,400.000
91/8/2021ATR-A106CLA7US20.00011.000800.000870.000800.000696,000.000640,000.00056,000.000
101/30/2021BBTR-A129CLA30CHI20.00011.000200.003,100.00620,000.00
111/21/2021ATR-A120CLA21CHI20.00011.000100.001,666.00166,600.00166,600.00
RES




but the right
PUR1.xlsx
ABCDEFGHIJKL
1ITEMCODEDESCIBEPRODUCTION BYQTYSTQTNMQTYUNIT PRICEUNIT PRICE1TOTALTOTAL1BALANCE
21/1/2021ATR-A107CLA8UK2,099.000123.000900.000920.000900.000828,000.000810,000.00018,000.000
31/2/2021ATR-A101CLA2 VBG LCHI300.000100.000300.000330.000300.00099,000.00090,000.0009,000.000
41/3/2021ATR-A102CLA3TAI120.000120.000400.000450.000400.000180,000.000160,000.00020,000.000
51/4/2021ATR-A100CLA1 23M-1IT100.000120.000200.000220.000200.00044,000.00040,000.0004,000.000
61/5/2021ATR-A103CLA4TR20.000122.000500.000560.000500.000280,000.000250,000.00030,000.000
71/6/2021ATR-A104CLA5EG20.00011.000600.000622.000600.000373,200.000360,000.00013,200.000
81/7/2021ATR-A105M230TU20.00012.000700.000722.000700.000505,400.000490,000.00015,400.000
91/8/2021ATR-A106CLA7US20.00011.000800.000870.000800.000696,000.000640,000.00056,000.000
101/30/2021BBTR-A129CLA30CHI20.00011.000200.003,100.00-620,000.00-620,000.00
111/21/2021ATR-A120CLA21CHI20.00011.000100.00-1,666.00-166,600.00166,600.00
RES

you can see some values are not right in the right location for each column.
last thing if it's possible show empty cell zero but should replace by hyphen as show in second picture.
 
Upvote 0
For the first 8 lines:
Unit price: from sheet2
Unit price1: from sheet1

But from the last 2 lines, your manual expected outcome
Unit price: from sheet1
Unit price1: from sheet2

Why?
 
Upvote 0
sorry !! this is my mistake
it should
sheet1=unitprice
sheet2=unitprice1
 
Upvote 0
Try again:
VBA Code:
Option Explicit
Sub add()
Dim i&, j&, s1, s2, res
With Sheets("Sheet1")
    s1 = .Range("A2:F" & .Cells(Rows.Count, "A").End(xlUp).Row).Value
End With
With Sheets("Sheet2")
    s2 = .Range("A2:F" & .Cells(Rows.Count, "A").End(xlUp).Row).Value
End With
With Sheets("RES")
    res = .Range("B2:L" & .Cells(Rows.Count, "B").End(xlUp).Row).Value
For i = 1 To UBound(res)
    For j = 1 To UBound(s1)
        If res(i, 1) = s1(j, 2) Then
            res(i, 7) = s1(j, 6)
            res(i, 9) = res(i, 6) * res(i, 7)
            Exit For
        End If
    Next
    For j = 1 To UBound(s2)
        If res(i, 1) = s2(j, 2) Then
            res(i, 8) = s2(j, 6)
            res(i, 10) = res(i, 6) * res(i, 8)
            Exit For
        End If
    Next
Next
.Range("H2:L1000000").ClearContents
.Range("B2").Resize(UBound(res), UBound(res, 2)).Value = res
.Range("L2").Resize(UBound(res), 1).Formula = "=K2-J2"
End With
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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