为什么是005,05和5相同的Excel VBA,即使它被转换为文本?

如果发票号码(如果我尝试input已经存储的发票)在同一列中有双重,三联…input,我会有一个提醒我的代码(无论如何)。 由于有发票号码00202或0-505,还有202和505,它提醒我这样的程序相同的数字。

Private Sub CommandButton1_Click() Dim dataRange As Range, oneCell As Range Set dataRange = ActiveSheet.Range("b7:b15") 'short range for testing For Each oneCell In dataRange If 1 < Application.CountIf(dataRange, oneCell.Value) Then oneCell.Offset(0, 1) = "Double!" End If Next oneCell End Sub 

这就是COUNTIF如何处理数字数据(它将在单元格中执行相同的操作)。 您可以使用SUMPRODUCT代替:

 Private Sub CommandButton1_Click() Dim dataRange As Range, oneCell As Range Set dataRange = ActiveSheet.Range("b7:b15") 'short range for testing For Each oneCell In dataRange ' if cell is empty or contains "" don't do anything If onecell.Value <> vbNullString Then ' evaluate simply evaluates the formula string passed to it. ' and SUMPRODUCT doesn't have the same number conversion issue as COUNTIF If 1 < ActiveSheet.Evaluate("SUMPRODUCT(--(" & dataRange.Address & "=" & oneCell.Address & "))") Then oneCell.Offset(0, 1) = "Double!" End If End If Next oneCell End Sub