It will be really helpful to be able to call the function that includes the dictionary because I want to use it to store a dictionary of values that I will use frequently in other spreadsheets. I can send a Key value to the function, but I can't obtain an Item value back from it. When I attempt it without the Debug.Print, it throws an error even if it appears to function for the Debug.Print.
Function location_Dict(loc_Code)
Dim loc_dict As Dictionary
Set loc_dict = New Dictionary
Debug.Print "In loc_dic and value is " & loc_Code
With loc_dict()
.Add Key:=21, Item:="Alamo, TN"
.Add Key:=27, Item:="Bay, AR"
.Add Key:=54, Item:="Cash, AR"
.Add Key:=3, Item:="Clarkton, MO"
.Add Key:=42, Item:="Dyersburg, TN"
.Add Key:=2, Item:="Hayti, MO"
.Add Key:=59, Item:="Hazel, KY"
.Add Key:=44, Item:="Hickman, KY"
.Add Key:=56, Item:="Leachville, AR"
.Add Key:=90, Item:="Senath, MO"
.Add Key:=91, Item:="Walnut Ridge, AR"
.Add Key:=87, Item:="Marmaduke, AR"
.Add Key:=12, Item:="Mason, TN"
.Add Key:=14, Item:="Matthews, MO"
.Add Key:=51, Item:="Newport, AR"
.Add Key:=58, Item:="Ripley, TN"
.Add Key:=4, Item:="Sharon, TN"
.Add Key:=72, Item:="Halls, TN"
.Add Key:=13, Item:="Humboldt, TN"
.Add Key:=23, Item:="Dudley, MO"
End With
Debug.Print loc_dict.Item(loc_Code)
End Function
I would pass loc_Code as "51" as an example and it makes it to the function if I try loc_dict.Item(loc_Code) without debug.print it will not accept it.