how to display result of Scripting dictionary

ravaz

Board Regular
Joined
Mar 25, 2008
Messages
196
How to I get the results of the below code into cell "A2" of sheet "Inv"

Code:
Private Sub Worksheet_Activate()
Dim x, i, ii, u(), dic As Object, z As String
Set dic = CreateObject("Scripting.Dictionary")
dic.CompareMode = vbTextCompare
x = Sheets("DB").Range("a1").CurrentRegion.Resize(, 11).Value
rcnt = UBound(x, 1)
ccnt = UBound(x, 2)
For i = 1 To rcnt
If x(i, 2) = "INVOICE" And x(i, 10) > 0 Then
z = x(i, 3)
    If Not dic.exists(z) Then
        ReDim u(1 To ccnt)
            For ii = 1 To ccnt: u(ii) = x(i, ii): Next
            dic.Add z, u
    End If
End If
Next i
Rows("2:" & Rows.Count).ClearContents
End Sub
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
@yky Preeti V cannot mark as solution, only the OP can do that ;)
 
Upvote 0
I know, but in this case the object returned is an array of arrays. Not just an array. You can't write this directly to a sheet without looping
VBA Code:
Sub test()
Dim x, i, ii, u(), dic As Object, z As String
Set dic = CreateObject("Scripting.Dictionary")
dic.CompareMode = vbTextCompare
x = Sheets("DB").Range("a1").CurrentRegion.Resize(, 11).Value
rcnt = UBound(x, 1)
ccnt = UBound(x, 2)
For i = 1 To rcnt
If x(i, 2) = "INVOICE" And x(i, 10) > 0 Then
z = x(i, 3)
    If Not dic.exists(z) Then
        ReDim u(1 To ccnt)
            For ii = 1 To ccnt: u(ii) = x(i, ii): Next
            dic.Add z, u
    End If
End If
Next i
'Rows("2:" & Rows.Count).ClearContents

Sheets("inv").Cells(2, 1).Resize(dic.Count, ccnt).Value = Application.Transpose(Application.Transpose(dic.items))
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,688
Members
449,117
Latest member
Aaagu

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