Finding x, and copying a different value on same row

KasperC

New Member
Joined
May 11, 2023
Messages
49
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hello,

I'm struggeling a bit to figure out how to solve this issue.

I'm trying to compare two data-sets in two different workbooks, where Everything is linked up to an "ID" in column A in "ws" and Column F in "wb1".
I want to check if the value in ws column 4 is the same as the same type of value in wb1, which is in column 42.

Problem is when it finds several occurenses, the code breaks and prints all kinds of wierd outputs, and not just for the "i" in question but for the rest of the returned values.

I'd like for it to print one of each of the mis-matching occurances between the data sets.
Unfortunantly I'm not able to "filter" or remove any copies of the same ID as there might be some different information connected to that ID copy somewhere else in the data-set which is not relevant for this.

The different numbers are:
ID: Is a number, several digits long
The value im trying to match: prices connected to said ID's

Any Ideas?

VBA Code:
    Set rng = ws1.Columns("F:F")
  
    For i = 2 To LastRow
        finn = ws.Cells(i, 1).Value
        Set cell = rng.Find(What:=finn, LookIn:=xlFormulas, LookAt:=xlWhole, MatchCase:=False)
      
        If cell Is Nothing Then
            Else
                wb1.Activate
                cell.Select
                p1 = ws.Cells(i, 4).Value
                p2 = ws1.Cells(ActiveCell.Row, 42).Value
              
                If Not p1 = p2 Then
                        LastRowN = wso.Range("A" & Rows.Count).End(xlUp).Row + 1
                        wso.Range("A" & LastRowN).Value = finn
                        wso.Range("B" & LastRowN).Value = p1
                        wso.Range("C" & LastRowN).Value = p2
                    End If
            End If
    Next i

Thank you for your time.

Regards,
Kasper C
 
Last edited by a moderator:

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Heres an example of what happens when there are two identical ID's:
1686657043265.png


As you may see, it starts to return some date, even though there are no dates in the selected column. Something is obviously wrong.
In addition, it ruins the rest of the outputs - for whatever reason I cant explain
 
Upvote 0
I found the issiue, there was a problem with the data-sets themselves. How can I delete a thread?
 
Upvote 0
Solution

Forum statistics

Threads
1,215,084
Messages
6,123,029
Members
449,092
Latest member
ikke

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