Creating a dictionary based on some input format?

jxb

Board Regular
Joined
Apr 19, 2007
Messages
172
Office Version
  1. 2010
Platform
  1. Windows
To all

As part of macro (to post process data), I am exploring the ideas of getting rid of a vlookup() creation by something that could potentially be more flexible (long term)

With the following data held in 1 tab

1673714101350.png

What would be the best way of creating a dictionary which would look like this shown on the right?

The thinking is that with a dictionary I can check the keys (cannot have duplicated) and I can loop over a range of cells in a column (later in the macro) and pick up the item (from the dico) easily (to write the value in a cell).

Will post some basic code I am testing shortly

Thanks in advance
John
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
works as I want

VBA Code:
Dim d           'Create a dictionary
Set d = CreateObject("Scripting.Dictionary")

'if string looks like <2:5,7,10:12>
 'remove 1st and last characters
 'split at each comma. one gets a string array - block of data
 'process each block - check if data as a colon
 'if yes then split (get block 2)
 
If InStr(asdatablock(i), sdelimcolon) <> 0 Then
    asdatablock2 = Split(asdatablock(i), sdelimcolon)
            
    ivalue = CInt(asdatablock2(0))
            
    While ivalue < CInt(asdatablock2(UBound(asdatablock2))) + 1
        If d.Exists(ivalue) = False Then
            d.Add ivalue, ipartname
        Else
            'Add Error
        End If
        ivalue = ivalue + 1
    Wend
            
Else
 'check and add value to dictionary as before
End If
 
Upvote 0
Solution

Forum statistics

Threads
1,223,954
Messages
6,175,603
Members
452,660
Latest member
Zatman

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