NOT expected result in macro

LoganTrk

New Member
Joined
Jan 24, 2019
Messages
17
Hello, my macro should do the following. It must be verified that all the “Project Code” declared in sheet 1704 are reflected in the “Project Code” field of sheet 1701. It works fine but when the same code is put several times on sheet 1704, it tells me that the code is not found on sheet 1701.



Code:
<code style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; margin: 0px; outline: 0px; padding: 0px; line-height: 12px;">Dim varrayC As Variant, varrayA As Variant
Dim lastRow As Long

Dim dict As Object
Dim j As Double

Set dict = CreateObject("scripting.dictionary")
' Definicion d rangos

lastRow = Hoja48.Range("A" & Rows.Count).End(xlUp).Row
varrayA = Hoja48.Range("A2:A" & lastRow).Value

lastRow = Hoja50.Range("A" & Rows.Count).End(xlUp).Row
varrayC = Hoja50.Range("A2:A" & lastRow).Value

On Error Resume Next
For i = 1 To UBound(varrayA, 1)
    dict.Add varrayA(i, 1), 1
Next

j = 10
' Comparar

For i = 1 To UBound(varrayC, 1)

    If dict.exists(varrayC(i, 1)) = False Then
                
        Hoja46.Cells(j, 66).Value = varrayC(i, 1)
            
       j = j + 1
      
   
    End If
Next i
</code>
sheet 1701

Code Name
CW222222 Sondaje


sheet 1704

Code System
CW222222 220
CW222222 220
CW222222 220
CW222222 220
CW222222 220
CW222222 220


Result

CW222222
CW222222
CW222222
CW222222
CW222222
CW222222


Expected result

no code, since it is found on sheet 1701

please help, I'm stuck


 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Why there are no sheet 1701 & 1704 mentioned in your code?
 
Upvote 0
cause sheet 1701 is sheet 48 or hoja48 in spanish , and sheet 1704 is hoja50 , and in hoja46 i put results
 
Upvote 0
cause sheet 1701 is sheet 48 or hoja48 in spanish , and sheet 1704 is hoja50 , and in hoja46 i put results

then I think hoja50 is the one that should be populated into dictionary, try setting the range in reverse:

Code:
lastRow = Hoja50.Range("A" & Rows.count).End(xlUp).Row
varrayA = Hoja50.Range("A2:A" & lastRow).Value

lastRow = Hoja48.Range("A" & Rows.count).End(xlUp).Row
varrayC = Hoja48.Range("A2:A" & lastRow).Value
 
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,340
Members
452,638
Latest member
Oluwabukunmi

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