VBA help - dictionary key and items

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
976
Office Version
  1. 2010
Platform
  1. Windows
Hi Team,

I am unable to print dictionary items , Attached are two examples.

This works:-
VBA Code:
Sub Dictionary_Excercise_1()

Dim dic1 As New Scripting.dictionary

dic1.Add "MrExcel", 10000

Range("A2").Resize(dic1.Count, 2).Value = Application.Transpose(Array(dic1.keys, dic1.items))
  

End Sub


This is not working.
VBA Code:
Sub Dictionary_Excercise_2()

Dim dic2 As New Scripting.dictionary

dic1.Add "MrExcel", [B]Array(10000, 20000, 30000)[/B]

Range("D2").Resize(dic2.Count, [B]3[/B]).Value = Application.Transpose(Array(dic2.keys, dic2.items))   'getting error type mismatch.
  

End Sub


Expected output Range D2

Book1
ABCDEFG
1Dictionary Example - 1Dictionary Example - 2
2MrExcel10000MrExcel100002000030000
Sheet2



Thanks
mg
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Hi Fluff,

Thank you so much got it, below worked.

Range("D2").Resize(dic2.Count, 3).Value = Application.Index(dic2.items, 0, 0)


Thanks
mg
 
Upvote 0
Glad you sorted it & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,461
Messages
6,124,953
Members
449,198
Latest member
MhammadishaqKhan

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