Index and match vertical and horizontal data

Blessy Clara

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

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
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
 
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,213,482
Messages
6,113,915
Members
448,532
Latest member
9Kimo3

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