Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating values in excel VBA dictionary

Tags:

excel

vba

I have a Dictionary which has school names as keys and arrays for values. Once the addition of the key,value pairs to the dictionary is done, I want to be able to update the values of the array after checking if certain conditions are met. However, the values don't get updated even if the conditions are met. Any thoughts?

Dim nre(0 To 2) As Boolean
nre(0) = False
nre(1) = False
nre(2) = False

Dim schdict
Set schdict = CreateObject("Scripting.Dictionary")

For i = 2 To numrows
    schname = ActiveSheet.Cells(i, schnamecolumn).Value
    category = ActiveSheet.Cells(i, categorycolumn).Value
    If schdict.Exists(schname) = False Then
        schdict.Add schname, nre
    End If

    If category = "New Placement" Then
        schdict.Item(schname)(0) = True
    ElseIf category = "Renomination" Then
        schdict.Item(schname)(1) = True
    Else
        schdict.Item(schname)(2) = True
    End If
Next i

MsgBox schdict.Item("Division 01")(0)
like image 815
CodeNewbie Avatar asked Nov 03 '13 11:11

CodeNewbie


1 Answers

Try this:

Create a second array:

Dim vArray as variant 

redim vArray(0 to 2) 

Then assign the dictionary array to the newly created array as such:

vArray = schdict.Item(schname)

Set the value of the array:

vArray(1) = True

And finally assign the array to the dictionary item:

schdict.Item(schname) = vArray 
like image 165
html_programmer Avatar answered Oct 06 '22 01:10

html_programmer