Index and match vertical and horizontal data

Blessy Clara

Board Regular
Joined
Mar 28, 2010
Messages
204
Office Version
  1. 365
Platform
  1. Windows
I have two excel sheets
Sheet 1 [TABLE="width: 500"]
<tbody>[TR]
[TD]productID[/TD]
[TD]18-5-2019[/TD]
[TD]17-5-2019[/TD]
[TD]16-5-2019[/TD]
[TD]15-5-2019[/TD]
[TD]for5 months....[/TD]
[/TR]
[TR]
[TD][TABLE="width: 206"]
<tbody>[TR]
[TD="class: xl63, width: 206"]32852314981[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]=?[/TD]
[TD]=[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][TABLE="width: 206"]
<tbody>[TR]
[TD="class: xl65, width: 206"]32796241751[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][TABLE="width: 206"]
<tbody>[TR]
[TD="class: xl65, width: 206"]32918411783[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]requirement[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][TABLE="width: 206"]
<tbody>[TR]
[TD="class: xl63, width: 206"]32852314981[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]100[/TD]
[TD]0[/TD]
[TD]25[/TD]
[TD]0[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
sheet 2
has transaction data
[TABLE="width: 500"]
<tbody>[TR]
[TD]productid[/TD]
[TD]date[/TD]
[TD]quantity[/TD]
[/TR]
[TR]
[TD] [TABLE="width: 86"]
<tbody>[TR]
[TD="width: 86, align: right"]32852314981[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]18-5-2019[/TD]
[TD]100[/TD]
[/TR]
[TR]
[TD][TABLE="width: 86"]
<tbody>[TR]
[TD="width: 86, align: right"]32852314981[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 74"]
<tbody>[TR]
[TD="class: xl65, width: 74"]16-05-019[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]25[/TD]
[/TR]
[TR]
[TD][TABLE="width: 86"]
<tbody>[TR]
[TD="width: 86, align: right"]32852314981[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 74"]
<tbody>[TR]
[TD="class: xl65, width: 74"]13-05-019[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD][TABLE="width: 206"]
<tbody>[TR]
[TD="class: xl65, width: 206"]32796241751[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]15-5-2019[/TD]
[TD]500[/TD]
[/TR]
[TR]
[TD]32796241751[/TD]
[TD]12-5-2019[/TD]
[TD]200[/TD]
[/TR]
[TR]
[TD]32796241751[/TD]
[TD]13-5-2019[/TD]
[TD]7[/TD]
[/TR]
</tbody>[/TABLE]

****** id="cke_pastebin" style="position: absolute; top: 224px; width: 1px; height: 1px; overflow: hidden; left: -1000px;">[TABLE="width: 500"]
<tbody>[TR]
[TD]18-5-2019[/TD]
[/TR]
</tbody>[/TABLE]
Requiremen</body>Requirement - I want to get the quantity sold for a specific product matched with the date and quantity in sheet 2 data
To Note - when the quantity for specific date in not available in sheet 2 - it can be give as n/a


Thank you
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi,

Below set up across A1:I7 for illustrative purposes only. Please change ranges to suit your actual data set.

[TABLE="class: tableizer-table"]
<tbody>[TR="class: tableizer-firstrow"]
[TH]productID[/TH]
[TH]18/05/2019[/TH]
[TH]17/05/2019[/TH]
[TH]16/05/2019[/TH]
[TH]15/05/2019[/TH]
[TH][/TH]
[TH]productid[/TH]
[TH]date[/TH]
[TH]quantity[/TH]
[/TR]
[TR]
[TD]32852314981[/TD]
[TD]100[/TD]
[TD]0[/TD]
[TD]25[/TD]
[TD]0[/TD]
[TD][/TD]
[TD]32852314981[/TD]
[TD]18/05/2019[/TD]
[TD]100[/TD]
[/TR]
[TR]
[TD]32796241751[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD]500[/TD]
[TD][/TD]
[TD]32852314981[/TD]
[TD]16/05/2019[/TD]
[TD]25[/TD]
[/TR]
[TR]
[TD]32918411783[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD][/TD]
[TD]32852314981[/TD]
[TD]13/05/2019[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]32796241751[/TD]
[TD]15/05/2019[/TD]
[TD]500[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]32796241751[/TD]
[TD]12/05/2019[/TD]
[TD]200[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]32796241751[/TD]
[TD]13/05/2019[/TD]
[TD]7[/TD]
[/TR]
</tbody>[/TABLE]

Formula in B2, copied down and across, is:

Code:
=IFERROR(INDEX($I$2:$I$7,MATCH(1,IF($G$2:$G$7=$A2,IF($H$2:$H$7=B$1,1)),0)),0)

Which needs committing with CTRL+SHIFT+ENTER due to its array nature.

Matty
 
Upvote 0
Hi Matty

Thank you very much for the formula - Great, it matches my exact requirement. However I do have a query - My Transaction Table is more than 1 million rows, in that case how do i change the range value.

Also the Column A records will be more than 50,000 records matched with dates running for 90 days - Please advice - thanks
 
Upvote 0
With a sample of your data run this macro.
But excel is not so fast to work with a million records, maybe you should try Access:


Code:
Option Explicit
Sub ID_Transaction()
    Dim sh1 As Worksheet, sh2 As Worksheet, rngID As Range
    Dim c As Range, r As Range, b As Range, f As Variant, cell As String
    
    Set sh1 = Sheets("Sheet1")
    Set sh2 = Sheets("Sheet2")
    
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    Application.StatusBar = False
    Set rngID = sh1.Range("A2", sh1.Range("A" & Rows.Count).End(xlUp))
    For Each c In rngID
        Application.StatusBar = "Searching row: " & c.Row & " of: " & rngID.Count
        Set r = sh2.Columns("A")
        Set b = r.Find(c.Value, LookAt:=xlWhole, LookIn:=xlValues)
        If Not b Is Nothing Then
            cell = b.Address
            Do
                f = Application.Match(b.Offset(, 1), sh1.Rows(1), 0)
                If Not IsError(f) Then
                    sh1.Cells(c.Row, f).Value = b.Offset(0, 2)
                End If
                Set b = r.FindNext(b)
            Loop While Not b Is Nothing And b.Address <> cell
        End If
    Next
    
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
    Application.StatusBar = False
        
    MsgBox "Done"
End Sub

Either way, let me know if you have any doubts
 
Upvote 0
Hi Matty

Thank you very much for the formula - Great, it matches my exact requirement. However I do have a query - My Transaction Table is more than 1 million rows, in that case how do i change the range value.

Also the Column A records will be more than 50,000 records matched with dates running for 90 days - Please advice - thanks

That is a fairly big data set for Excel to cope with.

In the absence of a proper database, e.g. SQL Server or Access, consider using Power Query instead. You could then carry out any data transformation there and pivot the data as required. And it will be quick, even on a data set of this size.

Matty
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
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