Efficient way to double loop through 2 dict

john316swan

Board Regular
Joined
Oct 13, 2016
Messages
66
Office Version
  1. 2019
Platform
  1. Windows
I have a list of unique IDs in one sheet, and a table that includes duplicated list of unique IDs and another column that contains scholarship names. I am trying to find the most efficient way to return all the unique scholarship names.

For example, in Sheets(1), column A, I have the list of id's
Column A (StudentID)
1
2
3
etc.

Then in Sheets(7), column A there is a list of duplicated IDs for every scholarship a student has, and in column D list each scholarship.
Column A (StudentID)Column D (AwardType)
1Presidential Scholar
1Ministry Worker
1Music
2Presidential Scholar
2Church Partner
2Theatre
3Provost Scholar
3Men Basketball
3Christian HS
3Music

Ideally I want a unique/unduplicated list of Column D (AwardType) so that I can transpose and export them as a column header. There are so many awards to lookup, that I want to limit it to the students in sheet 1 column A. Hope this makes sense, and thank you in advance for helping this rookie out.
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
Thanks for that, how about
VBA Code:
Sub Johnswan()
   Dim Dic As Object, Dic2 As Object
   Dim Cl As Range
   
   Set Dic = CreateObject("scripting.dictionary")
   Set Dic2 = CreateObject("scripting.dictionary")
   With Sheets("Sheet1")
      For Each Cl In .Range("A2", .Range("A" & Rows.Count).End(xlUp))
         Dic(Cl.Value) = Empty
      Next Cl
   End With
   With Sheets("Sheet2")
      For Each Cl In .Range("A2", .Range("A" & Rows.Count).End(xlUp))
         If Dic.Exists(Cl.Value) Then Dic2(Cl.Offset(, 3).Value) = Empty
      Next Cl
   End With
  Sheets("Sheet1").Range("B1").Resize(, Dic2.Count).Value = Dic2.Keys
End Sub
This will put the headers into sheet1 starting in B1
 
Upvote 0
Solution
Thank you @Fluff...essentially what I was looking for. Helped me find manual data input errors and cut load time.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,036
Messages
6,122,796
Members
449,095
Latest member
m_smith_solihull

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