skorpionkz
Well-known Member
- Joined
- Oct 1, 2013
- Messages
- 1,171
- Office Version
- 2016
Hi guys,
Could some one explain me how can I correctly add array to the dictionary and then read from it? I dont want to add every element of array, I want to save whole array. I have this code to create dictionary of the arrays:
I am not sure if this is correct and if it is how to read an array from dictionary?
Could some one explain me how can I correctly add array to the dictionary and then read from it? I dont want to add every element of array, I want to save whole array. I have this code to create dictionary of the arrays:
Rich (BB code):
Public dicRefData As New Scripting.Dictionary
Public Sub MyReference()
Dim arrMetric As Variant, arrData As Variant, vKey As Variant
Dim wb As Workbook
Dim ws As Worksheet
Dim lRow As Long, lCol As Long, l As Long
Set wb = SetWorkbook("ref_Data.csv")
Set ws = wb.ActiveSheet
With ws
lCol = .Rows(1).Find("*", SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column
lRow = .Cells.Find("*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
arrData = .Range(.Cells(1, 1), .Cells(lRow, lCol)).Value2
End With
wb.Close SaveChanges:=False
For l = LBound(arrData, 1) + 1 To UBound(arrData, 1)
If Not arrData(l, 1) = Empty Then dicRefData(arrData(l, 1)) = Empty
Next l
Debug.Print dicRefData.Count
lRow = 0
For Each vKey In dicRefData.Keys
Erase arrMetric
For l = LBound(arrData, 1) + 1 To UBound(arrData, 1)
lRow = lRow + 1
ReDim Preserve arrMetric(1 To 1, 1 To lRow)
If arrData(l, 1) = vKey Then
arrMetric(1, lRow) = arrData(l, 5) & " " & arrData(l, 6)
End If
Next l
Set dicRefData (vKey) = arrMetric
Next vKey
End Sub
I am not sure if this is correct and if it is how to read an array from dictionary?
Last edited: