Index and match vertical and horizontal data

Blessy Clara

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

Matty

Well-known Member
Joined
Feb 17, 2007
Messages
3,707
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
187
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
8,818
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,707
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
8,818
Office Version
2007
Platform
Windows
I'm glad to help you. Thanks for the feedback.
 

Forum statistics

Threads
1,081,981
Messages
5,362,535
Members
400,679
Latest member
alecalec202

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top