Results 1 to 12 of 12

How to understand and use CreateObject("Scripting.Dictionary")

Threaded View

Darthzo How to understand and use... 04-02-2013, 08:52 AM
stanleydgromjr Re: How to understand and use... 04-02-2013, 09:08 AM
stanleydgromjr Re: How to understand and use... 04-02-2013, 09:13 AM
Darthzo Re: How to understand and use... 04-02-2013, 10:22 AM
stanleydgromjr Re: How to understand and use... 04-02-2013, 10:53 AM
Darthzo Re: How to understand and use... 04-02-2013, 12:04 PM
stanleydgromjr Re: How to understand and use... 04-02-2013, 02:36 PM
stanleydgromjr Re: How to understand and use... 04-03-2013, 07:13 AM
Darthzo Re: How to understand and use... 04-03-2013, 01:21 PM
Darthzo Re: How to understand and use... 04-03-2013, 12:08 PM
stanleydgromjr Re: How to understand and use... 04-03-2013, 06:55 PM
stanleydgromjr Re: How to understand and use... 04-03-2013, 07:21 PM
  1. #12
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: How to understand and use CreateObject("Scripting.Dictionary")

    Darthzo,

    See the BOLD instructions (I hope they help).

    
    Option Explicit
    Sub GetUniqueListV2()
    ' stanleydgromjr, 04/03/2013
    ' http://www.excelforum.com/excel-programming-vba-macros/911706-how-to-understand-and-use-createobject-scripting-dictionary.html
    Dim rng As Range, rng2 As Range, c As Range, v
    
    With Sheets("A List")
    
      
      'set the variable rng
      '  to sheet "A List", range A2:A20
      Set rng = .Range("A2", .Range("A" & Rows.Count).End(xlUp))
    
    
    End With
    
    With Sheets("B List")
    
      
      'set the variable rng2
      '  to sheet "B List", range A2:A14
      Set rng2 = .Range("A2", .Range("A" & Rows.Count).End(xlUp))
    
    
    End With
    
    With CreateObject("Scripting.Dictionary")
    
      
      'tell the Scripting.Dictionary to compare text
      .CompareMode = vbTextCompare
    
      
      'c is a range variable
      '  for each cell in the range A2:A20
      For Each c In rng
    
      
        'if c is not equal to a space
        If c <> "" Then
    
          
          'then check, if the value of c is not already a key in the dictionary object
          If Not .Exists(c.Value) Then
    
          
            'if it is Not in the dictionary object, then add value of c to a key
            .Add c.Value, c.Value
    
    
          End If
        End If
      Next
    
      
      'the same instructions above relate to rng2 cells
    
      For Each c In rng2
        If c <> "" Then
          If Not .Exists(c.Value) Then
            .Add c.Value, c.Value
          End If
        End If
      Next
    
      
      'Transpose(Array(.Keys)) to variable array v
      v = Application.Transpose(Array(.Keys))
    
    End With
    
    With Sheets("Unique List of items")
    
      
      'clear the used range in Sheets("Unique List of items")
      .UsedRange.ClearContents
    
      
      With .Range("A1")
    
      
        'write the title to cell A1
        .Value = "Trust List"
    
        
        'format cell A1, Bold, and underline the characters
        .Font.Bold = True
        .Font.Underline = xlUnderlineStyleSingle
    
      End With
    
      
      'write the contents of v to A2:A25
      .Range("A2").Resize(UBound(v)) = v
    
      
      'sort A2:A25 ascending
      .Range("A2:A" & UBound(v) + 1).Sort key1:=.Range("A2"), order1:=1
    
      
      'autofit the columns width
      .Columns.AutoFit
    
      
      'activate/select Sheets("Unique List of items")
      .Activate
    
    
    End With
    End Sub
    Last edited by stanleydgromjr; 04-03-2013 at 07:38 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1