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

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
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,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

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