Index and match vertical and horizontal data

Blessy Clara

Board Regular
Joined
Mar 28, 2010
Messages
193
I have two excel sheets
Sheet 1
productID18-5-201917-5-201916-5-201915-5-2019for5 months....
32852314981

<tbody>
</tbody>
=?=
32796241751

<tbody>
</tbody>
32918411783

<tbody>
</tbody>
requirement
32852314981

<tbody>
</tbody>
1000250

<tbody>
</tbody>
sheet 2
has transaction data
productiddatequantity
32852314981

<tbody>
</tbody>
18-5-2019100
32852314981

<tbody>
</tbody>
16-05-019

<tbody>
</tbody>
25
32852314981

<tbody>
</tbody>
13-05-019

<tbody>
</tbody>
1
32796241751

<tbody>
</tbody>
15-5-2019500
3279624175112-5-2019200
3279624175113-5-20197

<tbody>
</tbody>

****** id="cke_pastebin" style="position: absolute; top: 224px; width: 1px; height: 1px; overflow: hidden; left: -1000px;">
18-5-2019

<tbody>
</tbody>
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
 

Some videos you may like

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Matty

Well-known Member
Joined
Feb 17, 2007
Messages
3,710
Hi,

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

productID18/05/201917/05/201916/05/201915/05/2019productiddatequantity
3285231498110002503285231498118/05/2019100
327962417510005003285231498116/05/201925
3291841178300003285231498113/05/20191
3279624175115/05/2019500
3279624175112/05/2019200
3279624175113/05/20197

<tbody>
</tbody>

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
 

Blessy Clara

Board Regular
Joined
Mar 28, 2010
Messages
193
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
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
11,279
Office Version
2007
Platform
Windows
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
 

Matty

Well-known Member
Joined
Feb 17, 2007
Messages
3,710
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
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
11,279
Office Version
2007
Platform
Windows
I'm glad to help you. Thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,096,458
Messages
5,450,575
Members
405,619
Latest member
mjh237

This Week's Hot Topics

Top