Any update >?? On Thursday, November 19, 2015 at 1:34:51 PM UTC+5:30, Mandeep Baluja wrote: > > Hi paul, > > But while correcting it this is giving error. please find the attached > file. it works on small amount of data easily but while using the data in > sheet it gives error. I admit by mistake i put demo in the code. > > Regards, > Mandeep baluja > > > > > > On Wednesday, November 18, 2015 at 6:07:13 PM UTC+5:30, Paul Schreiner > wrote: >> >> First: >> at the beginning of each module, use: >> >> Option Explicit >> >> (or in VB Editor, use Tools->Options and select "Require Variable >> Declaration") >> >> This will ensure that you "declare" each variable and don't >> unintentionally mis-spell a variable and thereby create a new variable. >> >> Now, once I added your sub to my own workbook, I found several variables >> that did not appear in a Dim statement. >> >> Now, perhaps you have these declared as "Public" or outside of this macro? >> >> Specifically, I found: >> >> i, arr, Arr1, d, Demo >> >> What is "Demo" ?? >> In this macro, you're not using it elsewhere, so when the statement: >> >> Sheet2.Range("b1").Resize(UBound(Demo), 1) = Application.Transpose(Arr1) >> runs, ubound(Demo) would be "empty" >> >> Without the "Option Explicit", VBA would automatically declare it as a >> type Variant. >> It is necessary for the variable in the UBound() function to be an array. >> If the variable is a "Variant", then the Ubound() function would indicate >> that the variable type does not "match" the type required. >> >> I suspect that you INTENDED the statement to be: >> >> Sheet2.Range("b2").Resize(UBound(Arr1), 1) = Application.Transpose(Arr1) >> >> (note: also changed to "b2" rather than "b1") >> >> *Paul* >> ----------------------------------------- >> >> >> >> >> >> >> >> *“Do all the good you can,By all the means you can,In all the ways you >> can,In all the places you can,At all the times you can,To all the people >> you can,As long as ever you can.” - John Wesley* >> ----------------------------------------- >> >> ------------------------------ >> *From:* Mandeep Baluja <rocke...@gmail.com> >> *To:* MS EXCEL AND VBA MACROS <excel-...@googlegroups.com> >> *Sent:* Wednesday, November 18, 2015 5:58 AM >> *Subject:* $$Excel-Macros$$ Dictionary_Query >> >> Hi paul, >> >> Will you please help me to learn this thing why this code gives error >> line was highlighted with comment you can search it with question mark in >> code ,I have alternatives to do this but why that line gives error but not >> the above ones. >> >> >> Sub Dictionary_Example() >> >> '------------------------------------------------------------- >> Dim Dic_obj As Object: 'This is a Dictionary object >> Dim lrow As Long: 'Find out the Last row >> '------------------------------------------------------------- >> >> 'Create a dictionary object >> Set Dic_obj = CreateObject("scripting.dictionary") >> >> 'Clear the dictonary object >> Dic_obj.RemoveAll >> >> With ActiveSheet >> lrow = .Cells(Rows.Count, 1).End(xlUp).Row >> For i = 2 To lrow >> If (Not (Dic_obj.exists(Cells(i, 1).Value))) Then >> Dic_obj.Add Cells(i, 1).Value, Cells(i, 2).Value >> Else >> Dic_obj.Item(Cells(i, 1).Value) = >> Dic_obj.Item(Cells(i, 1).Value) & "-" & Cells(i, 2).Value >> End If >> Next >> >> 'This is one dimensional array arr(0,659) >> 'Note:- Whenever keys copied into array it always one dimensional >> with lower bound 0 >> 'By using Transpose we will make it single dimensional >> arr = Dic_obj.keys >> >> 'Pasting it on the Sheet2 only unique keys >> Sheet2.Range("a2").Resize(UBound(arr), 1) = Application.Transpose(arr) >> >> 'Find out the Error >> arr1 = Dic_obj.items >> >> 'While running this below line We get an error type mismatch Why?? >> Because i don't want to run this below loop, _ >> for retrieving items from those keys. >> >> 'Sheet2.Range("b1").Resize(UBound(Demo), 1) = >> Application.Transpose(Arr1) >> >> d = Dic_obj.Count >> >> 'Retrieving Items of particular Key >> For i = 2 To Dic_obj.Count >> Sheet2.Cells(i, 2).Value = Dic_obj.Item(Sheet2.Cells(i, >> 1).Value) >> Next >> End With >> End Sub >> >> Regards, >> Mandeep baluja >> >> -- >> Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s >> =TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ >> https://www.facebook.com/discussexcel >> >> FORUM RULES >> >> 1) Use concise, accurate thread titles. Poor thread titles, like Please >> Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice >> will not get quick attention or may not be answered. >> 2) Don't post a question in the thread of another member. >> 3) Don't post questions regarding breaking or bypassing any security >> measure. >> 4) Acknowledge the responses you receive, good or bad. >> 5) Jobs posting is not allowed. >> 6) Sharing copyrighted material and their links is not allowed. >> >> NOTE : Don't ever post confidential data in a workbook. Forum owners and >> members are not responsible for any loss. >> --- >> You received this message because you are subscribed to the Google Groups >> "MS EXCEL AND VBA MACROS" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to excel-macros...@googlegroups.com. >> To post to this group, send email to excel-...@googlegroups.com. >> Visit this group at http://groups.google.com/group/excel-macros. >> For more options, visit https://groups.google.com/d/optout. >> >> >>
-- Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s =TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ https://www.facebook.com/discussexcel FORUM RULES 1) Use concise, accurate thread titles. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get quick attention or may not be answered. 2) Don't post a question in the thread of another member. 3) Don't post questions regarding breaking or bypassing any security measure. 4) Acknowledge the responses you receive, good or bad. 5) Jobs posting is not allowed. 6) Sharing copyrighted material and their links is not allowed. NOTE : Don't ever post confidential data in a workbook. Forum owners and members are not responsible for any loss. --- You received this message because you are subscribed to the Google Groups "MS EXCEL AND VBA MACROS" group. To unsubscribe from this group and stop receiving emails from it, send an email to excel-macros+unsubscr...@googlegroups.com. To post to this group, send email to excel-macros@googlegroups.com. Visit this group at http://groups.google.com/group/excel-macros. For more options, visit https://groups.google.com/d/optout.