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

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
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,214,563
Messages
6,120,248
Members
448,952
Latest member
kjurney

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