Replace vlookup using Array and dictionary

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
983
Office Version
  1. 2010
Platform
  1. Windows
Hi Team,

I want to store my data into Array. column [A:E]

k is my unique values ..... I need to extract matching values from data [A:E]

I know how to get using vlookup.

looking dictionary style. please assist. Thanks



1731905377683.png



Expected output is in LMN.


NameEnglishMathsScienceTotalNameScienceMathsEnglish
Sachin9262100248Sachin1006292
Dhoni806690236Yuvraj948362
Yuvraj628394239Ricky Ponting956366
Virat997997275Fleming859699
Steve waugh818892261
Ricky Ponting666395224
Adam Gilchrist979383273
Gayle709685251
Fleming999685280


thanks
mg
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
You mean index formula?
In G2 copied to full range.
Excel Formula:
=IFERROR(INDEX($B$2:$I$10,MATCH($F2,$A$2:$A$10,0),MATCH(G$1,$B$1:$F$1,0)),"")
 
Upvote 0
if you use the following formula in L2 and populate across the field, this should do what you want, and if you change a name or heading it will auto update:
Excel Formula:
=INDEX($A$1:$E$8,MATCH($K2,$A$1:$A$8,0),MATCH(L$1,$A$1:$E$1,0))
 
Upvote 0
If this is a learning material, (not a good example though)
Code:
Sub test()
    Dim a, i&, ii&, dic As Object
    Set dic = CreateObject("Scripting.Dictionary")
    a = [a1].CurrentRegion.Value
    For i = 2 To UBound(a, 1)
        For ii = 2 To UBound(a, 2)
            dic(Join(Array(a(i, 1), a(1, ii)), Chr(2))) = a(i, ii)
    Next ii, i
    With [l1].CurrentRegion
        .Offset(1, 1).ClearContents
        a = .Value
        For i = 2 To UBound(a, 1)
            For ii = 2 To UBound(a, 2)
                a(i, ii) = dic(Join(Array(a(i, 1), a(1, ii)), Chr(2)))
        Next ii, i
        .Value = a
    End With
End Sub
 
Upvote 0
Here an example with a double dictionary. Idea is to check if the name exists in the first dictionary before adding the record to the output dictionary

VBA Code:
Sub jec()
 Dim ar, ar2, j As Long
 Dim dic As Object, dic2 As Object
 
 ar = Cells(1).CurrentRegion
 ar2 = Cells(1, 11).CurrentRegion.Columns(1)
 
 Set dic = CreateObject("scripting.dictionary")
 Set dic2 = CreateObject("scripting.dictionary")
 
 For j = 1 To UBound(ar2)
   dic2(ar(j, 1)) = Empty
 Next
 
 For j = 1 To UBound(ar)
   If dic2.exists(ar(j, 1)) Then dic(ar(j, 1)) = Array(ar(j, 1), ar(j, 4), ar(j, 3), ar(j, 2))
 Next
   
 Cells(1, 11).Resize(dic.Count, 4) = Application.Index(dic.items, 0, 0)
End Sub
 
Upvote 0
Here an example with a double dictionary. Idea is to check if the name exists in the first dictionary before adding the record to the output dictionary
I am pretty sure that this loop is meant to be loading ar2 not ar.
Rich (BB code):
 For j = 1 To UBound(ar2)
   dic2(ar2(j, 1)) = Empty
 Next
 
  • Like
Reactions: JEC
Upvote 0
Hi All,

Thank you all for your help, I will go with JEC Solution.

I want to print values in different columns,
Read all rows and write different columns as per choice.


example

sheet1.Range("a1:d1000") read values

sheet2.range("A2:A100).unique records
sheet2.range("B2:b100).value = first matching column data
sheet2.range("d2:d100).value = second matching column data
sheet2.range("f2:f100).value = third matching column data
sheet2.range("g2:g100).value = fourth matching values



Thanks
mg
 
Upvote 0

Forum statistics

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