Match three columns with one column and pull numeric values

abdo meghari

Active Member
Joined
Aug 3, 2021
Messages
465
Office Version
  1. 2019
Hello
I have In & Out Balance sheet ,every month I will insert three columns (ARRIVED & SALES , STOCK ) also every month will get new data for items sheet .
I want matching column B:D for In & Out Balance with column B for items
and populate values in last columns AARIVED& SALES(AARIVED& SALES will be change in location after add new month )
should update n & Out Balance sheet when update items sheet .
original data before fill
TIRES REPORT.xlsm
ABCDEFGHIJKLM
2CategorySizePatternOriginArrivedSalesStock Arrived SalesStockArrivedSalesStock
3PSR (LRD)175/70R13B25INDO2001618405179179
4175/70R13EP150THI000001010
5185/70R13EP150INDO0000000
6175/65R14EP150INDO200201003030
7175/70R14EP150THI300300000
8175/70R14MY02THI110011005105105
9185/65R14TECTHI120012000120120
10185/65R14EP150INDO2000200223219219
11185/65R15B250JAP0000000
12195/60R15AR20INDO11011001111
13195/60R15EP150THI222200000
14195/60R15T001JAP0000000
15195/60R15150EZTHI0000000
16195/65R15MY02THI234023400234234
17195/65R15EP150THI444044400444444
18195/65R15EP150JAP44044004444
19195/65R15T001JAP55055005555
20195/55R16EP300THI0000000
21205/55R16RE003THI0000000
22205/65R15EP150INDO0000000
23205/70R15694JAP0006606666
24225/75R15CT697INDO0006606666
25235/95R15CD618JAP01-100-1-1
26255/70R15CD840THI0000000
27TTL1490391451164131582001582
28PSR (HRD)215/45R17T001JAP0000000
29215/50R17EP300THI34034003434
30215/55R17GR90INDO44044004444
31285/30R20RE0050AJAP0000000
32315/35R20SPORTJAP0003503535
33TTL7807835011300113
In & Out Balance
Cell Formulas
RangeFormula
J3,M28:M32,M3:M26,J28:J32,J8:J26,J5:J6J3=G3+H3-I3
E27:M27E27=SUM(E3:E26)
G28:G32,G3:G26G3=E3-F3
E33:M33E33=SUM(E28:E32)



TIRES REPORT.xlsm
ABCD
1ITEMSizeArrivedSales
21195/60R15 T001 JAP2010
32175/70R14 MY02 THI110
43205/55R16 RE003 THI2525
54195/60R15 AR20 INDO1112
65205/70R15 694 JAP20
76195/65R15 EP150 JAP33
87235/95R15C D618 JAP22
98285/30R20 RE0050A JAP12
109315/35R20 SPORT JAP22
11
12
13
14
15
16
17
18
19
20
21
items



I expect result like this
TIRES REPORT.xlsm
ABCDEFGHIJKLM
2CategorySizePatternOriginArrivedSalesStock Arrived SalesStockArrivedSalesStock
3PSR (LRD)175/70R13B25INDO2001618405179179
4175/70R13EP150THI000001010
5185/70R13EP150INDO0000000
6175/65R14EP150INDO200201003030
7175/70R14EP150THI300300000
8175/70R14MY02THI110011005105110215
9185/65R14TECTHI120012000120120
10185/65R14EP150INDO2000200223219219
11185/65R15B250JAP0000000
12195/60R15AR20INDO1101100111112120
13195/60R15EP150THI222200000
14195/60R15T001JAP000000201010
15195/60R15150EZTHI0000000
16195/65R15MY02THI234023400234234
17195/65R15EP150THI444044400444444
18195/65R15EP150JAP4404400443344
19195/65R15T001JAP55055005555
20195/55R16EP300THI0000000
21205/55R16RE003THI00000025250
22205/65R15EP150INDO0000000
23205/70R15694JAP000660662046
24225/75R15CT697INDO0006606666
25235/95R15CD618JAP01-100-12221
26255/70R15CD840THI0000000
27TTL1490391451164131582291601813
28PSR (HRD)215/45R17T001JAP0000000
29215/50R17EP300THI34034003434
30215/55R17GR90INDO44044004444
31285/30R20RE0050AJAP0000001212
32315/35R20SPORTJAP000350352213
33TTL780783501131222103
In & Out Balance
Cell Formulas
RangeFormula
J3,M28:M32,M3:M26,J28:J32,J8:J26,J5:J6J3=G3+H3-I3
E27:M27E27=SUM(E3:E26)
G28:G32,G3:G26G3=E3-F3
E33:M33E33=SUM(E28:E32)

thanks
 

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)
Hi @abdo meghari.

Note: The names of the sheets in the macro are: "In & Out Balance" and "items".

Please try this:
VBA Code:
Sub MatchThreeColumns()
  Dim sh1 As Worksheet, sh2 As Worksheet
  Dim f As Range, c As Range
  Dim dic As Object
  Dim kys As String
  Dim i As Long, col1 As Long, col2 As Long
  Dim a As Variant, b As Variant, itms As Variant
  
  Set sh1 = Sheets("In & Out Balance")
  Set sh2 = Sheets("items")
  Set dic = CreateObject("Scripting.Dictionary")
  
  a = sh1.Range("B3", sh1.Range("D" & Rows.Count).End(3)).Value
  ReDim b(1 To UBound(a, 1), 1 To 2)
  
  For i = 1 To UBound(a, 1)
    kys = Trim(a(i, 1)) & "|" & Trim(a(i, 2)) & "|" & Trim(a(i, 3))
    dic(kys) = i
  Next
  
  Set f = sh2.Range("1:1").Find(sh1.Range("K2").Value, , xlValues, xlWhole, , , False)
  If Not f Is Nothing Then
    col1 = f.Column
    
    Set f = sh2.Range("1:1").Find(sh1.Range("L2").Value, , xlValues, xlWhole, , , False)
    If Not f Is Nothing Then
      col2 = f.Column
      
      For Each c In sh2.Range("B2", sh2.Range("B" & Rows.Count).End(3))
        itms = Split(Trim(c.Value), " ")
        If UBound(itms) = 2 Then
          kys = itms(0) & "|" & itms(1) & "|" & itms(2)
          If dic.exists(kys) Then
            b(dic(kys), 1) = sh2.Cells(c.Row, col1)
            b(dic(kys), 2) = sh2.Cells(c.Row, col2)
          End If
        End If
      Next
      
      sh1.Range("K3").Resize(UBound(b), 2).Value = b
      
    Else
      MsgBox "Dos not exists Header " & sh1.Range("L2").Value
    End If
  Else
    MsgBox "Dos not exists Header " & sh1.Range("K2").Value
  End If
End Sub


---------------
I hope it helps you.
Cordially.
Dante Amor
---------------
 
Upvote 0
Hi Dante
there are two problems
1-when pull value should fill for the last columns ARRIVED & SALES . as I said
every month I will insert three columns (ARRIVED & SALES , STOCK )
it means the last columns could be N,O or Q,R for columns ARRIVED, SALES when every time insert three columns .it depends on matching for headers ARRIVED, SALES in last columns .
2- should not clear formula as in TTL row
thanks
 
Upvote 0
Hi Abdo:

You're right, it's my mistake, I hadn't understood the requirement correctly.

Please try this new macro:
VBA Code:
Sub MatchThreeColumns_v2()
  Dim sh1 As Worksheet, sh2 As Worksheet
  Dim f As Range
  Dim kys As String
  Dim i As Long, col1_1 As Long, col1_2 As Long, col2_1 As Long, col2_2 As Long
  
  Set sh1 = Sheets("In & Out Balance")
  Set sh2 = Sheets("items")
  
  Set f = sh1.Range("2:2").Find("Arrived", , xlValues, xlWhole, xlByColumns, xlPrevious, False)
  If f Is Nothing Then MsgBox "In & Out Balance. Does not exists Header Arrived": Exit Sub
  col1_1 = f.Column
  
  Set f = sh1.Range("2:2").Find("Sales", , xlValues, xlWhole, xlByColumns, xlPrevious, False)
  If f Is Nothing Then MsgBox "In & Out Balance. Does not exists Header Sales": Exit Sub
  col1_2 = f.Column
  
  Set f = sh2.Range("1:1").Find("Arrived", , xlValues, xlWhole, , , False)
  If f Is Nothing Then MsgBox "items. Does not exists Header Arrived": Exit Sub
  col2_1 = f.Column
        
  Set f = sh2.Range("1:1").Find("Sales", , xlValues, xlWhole, , , False)
  If f Is Nothing Then MsgBox "items. Does not exists Header Sales": Exit Sub
  col2_2 = f.Column
          
  For i = 3 To sh1.Range("B" & Rows.Count).End(3).Row
    If sh1.Range("B" & i).Value <> "TTL" And sh1.Range("C" & i).Value <> "" Then
      kys = Trim(sh1.Range("B" & i).Value) & " " & Trim(sh1.Range("C" & i).Value) & " " & Trim(sh1.Range("D" & i).Value)
      Set f = sh2.Range("B:B").Find(kys, , xlValues, xlWhole, , , False)
      If Not f Is Nothing Then
        sh1.Cells(i, col1_1).Value = sh2.Cells(f.Row, col2_1)
        sh1.Cells(i, col1_2).Value = sh2.Cells(f.Row, col2_2)
      End If
    End If
  Next
End Sub

Cordially.
Dante Amor
 
Upvote 1
Solution

Forum statistics

Threads
1,215,391
Messages
6,124,679
Members
449,179
Latest member
jacobsscoots

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