Bad code = CreateObject('scripting.dictionary") failure

Big Lar

Well-known Member
Joined
May 19, 2002
Messages
557
I’m attempting to add a “Y” to ws1, Column Q
This only adds “Y” from the last item in ws6.

I do not understand what I’m doing wrong.

Code:
Sub MacroUpdateY2()
   Dim Cl As Range
   Dim sKey As String
   Dim ws1 As Worksheet
   Dim ws6 As Worksheet
   Set ws6 = Sheets("6")
   Set ws1 = Sheets("1")
 
   With CreateObject("scripting.dictionary")
      For Each Cl In ws6.Range("A2", ws6.Range("A" & Rows.Count).End(xlUp))
         sKey = Trim(Cl.Value)
      Next Cl
 
      For Each Cl In ws1.Range("C2", ws1.Range("C" & Rows.Count).End(xlUp))
         If sKey = (Cl.Value) Then
 
    Cl.Offset(, 14).Value = "Y"
        
End If
  Next Cl
   End With
 
End Sub
<strike></strike>
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Try
Code:
Sub BigLar()
   Dim Cl As Range
   Dim ws1 As Worksheet
   Dim ws6 As Worksheet
   Set ws6 = Sheets("6")
   Set ws1 = Sheets("1")
 
   With CreateObject("scripting.dictionary")
      For Each Cl In ws6.Range("A2", ws6.Range("A" & Rows.Count).End(xlUp))
         .Item(Trim(Cl.Value)) = Empty
      Next Cl
 
      For Each Cl In ws1.Range("C2", ws1.Range("C" & Rows.Count).End(xlUp))
         If .Exists(Trim(Cl.Value)) Then Cl.Offset(, 14).Value = "Y"
      Next Cl
   End With
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,021
Latest member
Justyna P

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