My excel macro does not automatically recognize all numbers that are equal

时间:2017-07-12 08:20:53

标签: excel vba excel-vba

I am trying to compare two different datasets, and have written an Excel macro to do so, for code see below. My problem is that when I paste numbers from the external data, and my macro compares it with the data in my warehouse, for some cells it does not recognize that they are equal and I get the message "Deviance". However if I click into these cells, and don't edit them just click into them and press enter the macro recognizes that they are equal, and returns "OK".

Macro code:

Function compare(relevant, source 1, Source 2, n)

 deviance = False

 For i = 1 To n
     If relevant(1, i) <> "" Then
    If broker(1, i) <> nhc(1, i) Then deviance = True
End If
 Next i

If deviance Then
   compare = "Deviance"
   Else
   compare = "OK"
End If 

In Excel the system looks like below.

enter image description here

0 个答案:

没有答案